lunibee 0.2.3 → 0.2.4

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.
Files changed (61) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +225 -225
  3. package/dist/builders/attachment.d.ts +8 -0
  4. package/dist/builders/commands.d.ts +122 -65
  5. package/dist/builders/components.d.ts +10 -31
  6. package/dist/builders/embed.d.ts +66 -33
  7. package/dist/builders/index.js +97 -131
  8. package/dist/builders/index.js.map +8 -8
  9. package/dist/collection/cache.d.ts +13 -6
  10. package/dist/collection/index.d.ts +90 -17
  11. package/dist/collection/index.js +442 -266
  12. package/dist/collection/index.js.map +4 -4
  13. package/dist/core/index.d.ts +8 -0
  14. package/dist/core/index.js +607 -352
  15. package/dist/core/index.js.map +47 -47
  16. package/dist/core/permissions.d.ts +7 -3
  17. package/dist/formatters/index.js +9 -5
  18. package/dist/formatters/index.js.map +3 -3
  19. package/dist/handlers/index.js +5 -10
  20. package/dist/handlers/index.js.map +3 -3
  21. package/dist/index.js +769 -587
  22. package/dist/index.js.map +65 -65
  23. package/dist/managers/base.d.ts +22 -14
  24. package/dist/managers/index.d.ts +2 -1
  25. package/dist/managers/index.js +445 -276
  26. package/dist/managers/index.js.map +26 -26
  27. package/dist/managers/message.d.ts +7 -3
  28. package/dist/rest/errors.d.ts +14 -7
  29. package/dist/rest/index.d.ts +24 -12
  30. package/dist/rest/index.js +54 -17
  31. package/dist/rest/index.js.map +14 -14
  32. package/dist/rest/redis.d.ts +1 -1
  33. package/dist/rest/route.d.ts +8 -4
  34. package/dist/rest/routes.d.ts +102 -48
  35. package/dist/rest/transport.d.ts +10 -5
  36. package/dist/rest/webhook.d.ts +9 -5
  37. package/dist/sharding/bus.d.ts +34 -17
  38. package/dist/sharding/index.d.ts +34 -17
  39. package/dist/sharding/index.js +64 -32
  40. package/dist/sharding/index.js.map +17 -17
  41. package/dist/structures/base.d.ts +19 -10
  42. package/dist/structures/channels.d.ts +28 -14
  43. package/dist/structures/index.js +9 -59
  44. package/dist/structures/index.js.map +19 -18
  45. package/dist/structures/interactions.d.ts +96 -48
  46. package/dist/structures/resources.d.ts +88 -44
  47. package/dist/types/gateway.d.ts +1 -1
  48. package/dist/types/index.js +20 -22
  49. package/dist/types/index.js.map +4 -4
  50. package/dist/utils/index.js.map +2 -2
  51. package/dist/voice/index.d.ts +12 -4
  52. package/dist/voice/index.js +14 -18
  53. package/dist/voice/index.js.map +3 -3
  54. package/dist/ws/decoder.d.ts +6 -2
  55. package/dist/ws/index.d.ts +25 -13
  56. package/dist/ws/index.js +63 -31
  57. package/dist/ws/index.js.map +14 -14
  58. package/dist/ws/protocol.d.ts +10 -2
  59. package/dist/ws/session.d.ts +14 -4
  60. package/dist/ws/state.d.ts +22 -11
  61. package/package.json +15 -14
@@ -4,21 +4,28 @@ export interface CacheOptions {
4
4
  maxSize?: number;
5
5
  /** Time-to-live in milliseconds. Omit to disable expiration. */
6
6
  ttl?: number;
7
- /** Sweep interval in milliseconds. */
7
+ /**
8
+ * Accepted for compatibility and still validated. Expired entries are now
9
+ * dropped at their deadline, so no periodic sweep is needed.
10
+ */
8
11
  sweepInterval?: number;
9
12
  }
10
- /** Bounded cache with TTL expiration and explicit invalidation support. */
13
+ /**
14
+ * Bounded cache with a fixed TTL, least-recently-used eviction and explicit
15
+ * invalidation. A thin policy layer over {@link Collection}: reads promote an
16
+ * entry but do not extend its TTL.
17
+ */
11
18
  export declare class Cache<K, V> {
12
19
  #private;
13
20
  /** Creates a cache using the supplied retention policy. */
14
21
  constructor(options?: CacheOptions);
15
22
  /** Number of currently live entries. */
16
23
  get size(): number;
17
- /** Reads a live entry. */
24
+ /** Reads a live entry and marks it most recently used. */
18
25
  get(key: K): V | undefined;
19
26
  /** Returns whether a live entry exists. */
20
27
  has(key: K): boolean;
21
- /** Stores an entry and evicts the oldest entries when the bound is exceeded. */
28
+ /** Stores an entry and evicts the least recently used ones when the bound is exceeded. */
22
29
  set(key: K, value: V): this;
23
30
  /** Invalidates one key. */
24
31
  delete(key: K): boolean;
@@ -26,9 +33,9 @@ export declare class Cache<K, V> {
26
33
  clear(): void;
27
34
  /** Invalidates every entry matching a predicate. */
28
35
  invalidate(predicate: (value: V, key: K) => boolean): number;
29
- /** Removes expired entries and returns the number removed. */
36
+ /** Removes expired entries now and returns the number removed. */
30
37
  sweep(): number;
31
- /** Stops the background sweeper and releases its timer. */
38
+ /** Kept for compatibility: there is no background sweeper to stop. */
32
39
  dispose(): void;
33
40
  /** Returns live cached values. */
34
41
  values(): V[];
@@ -4,6 +4,8 @@ export interface CollectionOptions<K = unknown, V = unknown> {
4
4
  ttl?: number;
5
5
  /** Maximum entries stored with `set()`; least-recently-used are evicted past it. `setWithoutTTL()` entries are never counted or evicted. */
6
6
  maxSize?: number;
7
+ /** Whether a read restarts a TTL entry's window. Default `true`; with `false` an entry lapses a fixed time after it was set, and reads only mark it recently used. */
8
+ slide?: boolean;
7
9
  /** Called after an entry is removed automatically, with why. Exceptions are swallowed. */
8
10
  onEvict?: (key: K, value: V, reason: EvictionReason) => void;
9
11
  }
@@ -11,11 +13,27 @@ export interface CollectionOptions<K = unknown, V = unknown> {
11
13
  export type EvictionReason = "expired" | "evicted";
12
14
  /** Cumulative counters from {@link Collection.stats}. */
13
15
  export interface CollectionStats {
14
- /** `get`/`peek` calls that found a value. */ hits: number;
15
- /** `get`/`peek` calls that found nothing. */ misses: number;
16
- /** Entries removed because their TTL lapsed. */ expired: number;
17
- /** Entries removed to stay within `maxSize`. */ evicted: number;
16
+ /** `get`/`peek` calls that found a value. */
17
+ hits: number;
18
+ /** `get`/`peek` calls that found nothing. */
19
+ misses: number;
20
+ /** Entries removed because their TTL lapsed. */
21
+ expired: number;
22
+ /** Entries removed to stay within `maxSize`. */
23
+ evicted: number;
18
24
  }
25
+ /** What `merge()` does with one entry: keep it with `value`, or drop it. */
26
+ export type Keep<V> = {
27
+ keep: true;
28
+ value: V;
29
+ } | {
30
+ keep: false;
31
+ };
32
+ /**
33
+ * A `Collection` seen read-only: every method that does not change it. Pass it
34
+ * where you only read, so a function cannot add to or remove from the cache.
35
+ */
36
+ export type ReadonlyCollection<K, V> = Omit<Collection<K, V>, "set" | "setWithoutTTL" | "delete" | "clear" | "ensure" | "forEach" | "get" | "sweep" | "purge"> & ReadonlyMap<K, V>;
19
37
  /**
20
38
  * A keyed collection for Lunibee resource and application state.
21
39
  *
@@ -50,6 +68,14 @@ export declare class Collection<K, V> extends Map<K, V> {
50
68
  setWithoutTTL(key: K, value: V): this;
51
69
  /** Reads a value; restarts a TTL entry's window and promotes it. */
52
70
  get(key: K): V | undefined;
71
+ /**
72
+ * Returns the value for `key`, or stores and returns what `factory`
73
+ * makes. Reading counts as a `get()` (restarts the TTL, marks it recently
74
+ * used); creating stores with `set()`, so `ttl` applies.
75
+ * @param factory Called with the key and this collection only when the key is missing; if it throws, nothing is stored.
76
+ * @param ttl TTL in ms for a created entry; defaults to the collection's.
77
+ */
78
+ ensure(key: K, factory: (key: K, collection: this) => V, ttl?: number): V;
53
79
  /** Reads a value without restarting its TTL or promoting it. */
54
80
  peek(key: K): V | undefined;
55
81
  /** Cumulative hit, miss, expiry and eviction counters (a copy). */
@@ -77,8 +103,12 @@ export declare class Collection<K, V> extends Map<K, V> {
77
103
  lastKey(): K | undefined;
78
104
  /** Finds the first value matching a predicate. */
79
105
  find(predicate: (value: V, key: K, collection: this) => boolean): V | undefined;
106
+ /** Finds the last value (in insertion order) matching a predicate. */
107
+ findLast(predicate: (value: V, key: K, collection: this) => boolean): V | undefined;
108
+ /** Finds the key of the last entry (in insertion order) matching a predicate. */
109
+ findLastKey(predicate: (value: V, key: K, collection: this) => boolean): K | undefined;
80
110
  /** Returns all values matching a predicate. */
81
- filter(predicate: (value: V, key: K, collection: this) => boolean): Collection<K, V>;
111
+ filter(predicate: (value: V, key: K, collection: this) => boolean): this;
82
112
  /** Transforms every stored value into an array. */
83
113
  map<T>(transform: (value: V, key: K, collection: this) => T): T[];
84
114
  /** Returns whether at least one stored value satisfies a predicate. */
@@ -94,7 +124,7 @@ export declare class Collection<K, V> extends Map<K, V> {
94
124
  /** Returns a plain array of entries. */
95
125
  entriesArray(): [K, V][];
96
126
  /** Returns a new collection with the same entries. */
97
- clone(): Collection<K, V>;
127
+ clone(): this;
98
128
  /** Returns whether all supplied keys are present. */
99
129
  hasAll(...keys: K[]): boolean;
100
130
  /** Returns whether at least one supplied key is present. */
@@ -110,15 +140,46 @@ export declare class Collection<K, V> extends Map<K, V> {
110
140
  /** Returns the collection's last matching entry as a tuple. */
111
141
  lastEntry(): [K, V] | undefined;
112
142
  /** Returns a new Collection containing elements from both collections. */
113
- union(other: Collection<K, V>): Collection<K, V>;
143
+ union(other: ReadonlyCollection<K, V>): this;
114
144
  /** Returns a new Collection containing only elements present in both collections. */
115
- intersection(other: Collection<K, V>): Collection<K, V>;
145
+ intersection(other: ReadonlyCollection<K, V>): this;
116
146
  /** Returns a new Collection containing elements present in this collection but not the other. */
117
- difference(other: Collection<K, V>): Collection<K, V>;
147
+ difference(other: ReadonlyCollection<K, V>): this;
118
148
  /** Splits the collection into two collections based on a predicate.
119
149
  * @returns `[passing, failing]` — entries satisfying the predicate, then those that don't.
120
150
  */
121
- partition(predicate: (value: V, key: K, collection: this) => boolean): [Collection<K, V>, Collection<K, V>];
151
+ partition(predicate: (value: V, key: K, collection: this) => boolean): [this, this];
152
+ /** Returns the entries of both collections that are in only one of them. */
153
+ symmetricDifference(other: ReadonlyCollection<K, V>): this;
154
+ /** Returns a new Collection with this one's entries followed by each of `collections`'; a later collection wins a shared key. */
155
+ concat(...collections: ReadonlyCollection<K, V>[]): this;
156
+ /**
157
+ * Combines this collection with `other`, deciding per key what to keep.
158
+ * @param whenInSelf Called for a key only in this collection.
159
+ * @param whenInOther Called for a key only in `other`.
160
+ * @param whenInBoth Called for a key in both.
161
+ * @returns A new collection of the entries the callbacks kept, in this collection's order, then `other`'s new keys.
162
+ */
163
+ merge<T, R>(other: ReadonlyCollection<K, T>, whenInSelf: (value: V, key: K) => Keep<R>, whenInOther: (valueOther: T, key: K) => Keep<R>, whenInBoth: (value: V, valueOther: T, key: K) => Keep<R>): Collection<K, R>;
164
+ /** Returns whether `other` holds the same keys with `===` equal values. Neither side's TTL or recency is touched. */
165
+ equals(other: ReadonlyCollection<K, V> | null | undefined): boolean;
166
+ /** Returns a new collection with the same keys and each value passed through `transform`. */
167
+ mapValues<T>(transform: (value: V, key: K, collection: this) => T): Collection<K, T>;
168
+ /** Returns a new collection with the entries in reverse order. */
169
+ toReversed(): this;
170
+ /** Same as {@link sorted}, under the name the standard `Array` uses. */
171
+ toSorted(comparator?: (a: V, b: V, aKey: K, bKey: K) => number): this;
172
+ /**
173
+ * Groups `items` by the key `keySelector` returns for each.
174
+ * @param keySelector Called with each item and its index.
175
+ * @returns A new collection from each key to its items, in input order.
176
+ */
177
+ static groupBy<K, V>(items: Iterable<V>, keySelector: (item: V, index: number) => K): Collection<K, V[]>;
178
+ /**
179
+ * Builds a collection from `entries`, merging values that share a key.
180
+ * @param combine Called with the value stored so far, the new one and the key; its result is stored.
181
+ */
182
+ static combineEntries<K, V>(entries: Iterable<readonly [K, V]>, combine: (firstValue: V, secondValue: V, key: K) => V): Collection<K, V>;
122
183
  /** Calls `fn` with this collection and returns the collection unchanged.
123
184
  * Useful for inserting debug side-effects in a chain without breaking the flow.
124
185
  */
@@ -127,18 +188,30 @@ export declare class Collection<K, V> extends Map<K, V> {
127
188
  flatMap<T>(transform: (value: V, key: K, collection: this) => T[]): T[];
128
189
  /** Reduces the collection to a single value. */
129
190
  reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue: T): T;
191
+ /** Like {@link reduce}, but from the last entry to the first. */
192
+ reduceRight<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue: T): T;
130
193
  /** Returns a new Collection with entries sorted by comparator (non-mutating).
131
194
  * Defaults to insertion order if no comparator is provided.
132
195
  */
133
- sorted(comparator?: (a: V, b: V, aKey: K, bKey: K) => number): Collection<K, V>;
134
- /** Returns a random value from the collection, or `undefined` if empty.
135
- * Uses `Math.random()` (fast, non-cryptographic) — do not use for security-sensitive
136
- * selection such as tokens or secrets. */
196
+ sorted(comparator?: (a: V, b: V, aKey: K, bKey: K) => number): this;
197
+ /**
198
+ * Returns a random value, or `undefined` if empty. With `amount`, returns
199
+ * that many different values (all of them, shuffled, when `amount` is at
200
+ * least the size).
201
+ * Uses `Math.random()` (fast, non-cryptographic): do not use it for
202
+ * security-sensitive selection such as tokens or secrets.
203
+ * @param amount How many values to pick.
204
+ * @throws {RangeError} If `amount` is not a non-negative integer.
205
+ */
137
206
  random(): V | undefined;
138
- /** Returns a random key from the collection, or `undefined` if empty.
139
- * Uses `Math.random()` (fast, non-cryptographic) — do not use for security-sensitive
140
- * selection such as tokens or secrets. */
207
+ random(amount: number): V[];
208
+ /**
209
+ * Returns a random key, or `undefined` if empty. With `amount`, returns
210
+ * that many different keys. Same randomness and errors as {@link random}.
211
+ * @param amount How many keys to pick.
212
+ */
141
213
  randomKey(): K | undefined;
214
+ randomKey(amount: number): K[];
142
215
  /** Returns the value at a given insertion-order index (supports negative indices). */
143
216
  at(index: number): V | undefined;
144
217
  /** Returns the key at a given insertion-order index (supports negative indices). */