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