lunibee 0.3.2 → 0.3.3

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.
@@ -1,4 +1,11 @@
1
1
  import { Collection } from "@lunibee/collection";
2
+ /**
3
+ * Copies a structure's own fields onto the cached instance. A key loop: on Bun,
4
+ * Object.assign into an existing object is about twice as slow, on every event.
5
+ * Structures hold no symbol-keyed fields.
6
+ * @internal
7
+ */
8
+ export declare function assignFields<T extends object>(into: T, from: T): T;
2
9
  /** Splits the audit-log `reason` off an options object, so it becomes a header, not a body field. */
3
10
  export declare function splitReason<T extends {
4
11
  reason?: string;
@@ -901,6 +901,13 @@ class Collection extends Map {
901
901
  }
902
902
 
903
903
  // packages/managers/src/base.ts
904
+ function assignFields(into, from) {
905
+ const target = into;
906
+ const source = from;
907
+ for (const key of Object.keys(source))
908
+ target[key] = source[key];
909
+ return into;
910
+ }
904
911
  function splitReason(options) {
905
912
  const { reason, ...payload } = options;
906
913
  return [payload, reason];
@@ -1001,7 +1008,7 @@ class ResourceManager extends Manager {
1001
1008
  const key = this.#key(resource);
1002
1009
  const existing = this.get(key);
1003
1010
  if (existing !== undefined && existing !== resource && typeof existing === "object" && existing !== null) {
1004
- Object.assign(existing, resource);
1011
+ assignFields(existing, resource);
1005
1012
  this.set(key, existing);
1006
1013
  return existing;
1007
1014
  }
@@ -1015,7 +1022,7 @@ class ResourceManager extends Manager {
1015
1022
  // packages/rest/package.json
1016
1023
  var package_default = {
1017
1024
  name: "@lunibee/rest",
1018
- version: "0.3.2",
1025
+ version: "0.3.3",
1019
1026
  type: "module",
1020
1027
  module: "./src/index.ts",
1021
1028
  types: "./src/index.ts",
@@ -1422,7 +1429,7 @@ class Channel extends BaseStructure {
1422
1429
  permissionOverwrites;
1423
1430
  partial;
1424
1431
  #context;
1425
- constructor(data, context, options = {}) {
1432
+ constructor(data, context, options) {
1426
1433
  super(data.id);
1427
1434
  if (!Number.isInteger(data.type) || data.type < 0)
1428
1435
  throw new RangeError("A Discord channel requires a valid channel type.");
@@ -1435,7 +1442,7 @@ class Channel extends BaseStructure {
1435
1442
  this.rateLimitPerUser = data.rate_limit_per_user;
1436
1443
  this.position = data.position;
1437
1444
  this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
1438
- this.partial = options.partial ?? false;
1445
+ this.partial = options?.partial ?? false;
1439
1446
  this.#context = context;
1440
1447
  }
1441
1448
  send(options) {
@@ -2730,7 +2737,7 @@ class MessageManager {
2730
2737
  const existing = this.cache.peek(data.id);
2731
2738
  const message = new Message(data, this.#context);
2732
2739
  if (existing) {
2733
- Object.assign(existing, message);
2740
+ assignFields(existing, message);
2734
2741
  return existing;
2735
2742
  }
2736
2743
  if (this.#caching)
@@ -2907,7 +2914,7 @@ class EmojiManager extends Manager {
2907
2914
  #merge(key, emoji) {
2908
2915
  const existing = this.get(key);
2909
2916
  if (existing) {
2910
- Object.assign(existing, emoji);
2917
+ assignFields(existing, emoji);
2911
2918
  return existing;
2912
2919
  }
2913
2920
  this.set(key, emoji);
@@ -3794,7 +3801,7 @@ class ChannelManager extends Manager {
3794
3801
  #merge(channel) {
3795
3802
  const existing = this.get(channel.id);
3796
3803
  if (existing && existing.type === channel.type) {
3797
- Object.assign(existing, channel);
3804
+ assignFields(existing, channel);
3798
3805
  return existing;
3799
3806
  }
3800
3807
  this.set(channel.id, channel);
@@ -3804,9 +3811,14 @@ class ChannelManager extends Manager {
3804
3811
  return this.set(channel.id, channel);
3805
3812
  }
3806
3813
  deleteGuildChannels(guildId) {
3814
+ const ids = [];
3815
+ this.cache.forEach((channel, id) => {
3816
+ if (channel.guildId === guildId)
3817
+ ids.push(id);
3818
+ });
3807
3819
  let removed = 0;
3808
- for (const channel of this.values())
3809
- if (channel.guildId === guildId && this.delete(channel.id))
3820
+ for (const id of ids)
3821
+ if (this.delete(id))
3810
3822
  removed++;
3811
3823
  return removed;
3812
3824
  }
@@ -4047,4 +4059,4 @@ export {
4047
4059
  toRequest
4048
4060
  };
4049
4061
 
4050
- //# debugId=FBBCAAAFD8D05B9864756E2164756E21
4062
+ //# debugId=2CD7EF31353EB8CE64756E2164756E21