lunibee 0.3.1 → 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.
- package/dist/builders/attachment.d.ts +1 -0
- package/dist/builders/clone.d.ts +10 -0
- package/dist/builders/commands.d.ts +1 -1
- package/dist/builders/components.d.ts +24 -5
- package/dist/builders/index.js +64 -17
- package/dist/builders/index.js.map +10 -9
- package/dist/collection/index.d.ts +1 -0
- package/dist/collection/index.js +297 -19
- package/dist/collection/index.js.map +5 -4
- package/dist/collection/redis.d.ts +98 -0
- package/dist/core/collector.d.ts +8 -0
- package/dist/core/events.d.ts +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +6242 -4733
- package/dist/core/index.js.map +47 -40
- package/dist/core/permissions.d.ts +3 -402
- package/dist/core/redis-cache.d.ts +85 -0
- package/dist/formatters/index.d.ts +5 -1
- package/dist/formatters/index.js +7 -3
- package/dist/formatters/index.js.map +3 -3
- package/dist/handlers/index.js +11 -2
- package/dist/handlers/index.js.map +3 -3
- package/dist/index.js +8688 -6136
- package/dist/index.js.map +67 -59
- package/dist/managers/application.d.ts +10 -6
- package/dist/managers/base.d.ts +11 -1
- package/dist/managers/guild.d.ts +3 -1
- package/dist/managers/index.d.ts +6 -1
- package/dist/managers/index.js +383 -109
- package/dist/managers/index.js.map +20 -23
- package/dist/managers/member.d.ts +3 -1
- package/dist/managers/message.d.ts +13 -4
- package/dist/managers/thread.d.ts +3 -3
- package/dist/rest/decoder.d.ts +2 -0
- package/dist/rest/errors.d.ts +5 -2
- package/dist/rest/headers.d.ts +31 -0
- package/dist/rest/identity.d.ts +31 -0
- package/dist/rest/index.d.ts +97 -6
- package/dist/rest/index.js +1355 -220
- package/dist/rest/index.js.map +16 -13
- package/dist/rest/limiter.d.ts +75 -10
- package/dist/rest/redis.d.ts +103 -22
- package/dist/rest/scheduler.d.ts +13 -0
- package/dist/rest/store.d.ts +135 -12
- package/dist/rest/telemetry.d.ts +151 -0
- package/dist/rest/webhook.d.ts +18 -6
- package/dist/sharding/bus.d.ts +4 -2
- package/dist/sharding/cluster.d.ts +29 -1
- package/dist/sharding/health.d.ts +1 -1
- package/dist/sharding/host.d.ts +13 -2
- package/dist/sharding/identify.d.ts +2 -0
- package/dist/sharding/index.d.ts +8 -0
- package/dist/sharding/index.js +579 -65
- package/dist/sharding/index.js.map +17 -15
- package/dist/sharding/leader.d.ts +34 -0
- package/dist/sharding/remote.d.ts +36 -2
- package/dist/sharding/supervisor.d.ts +1 -1
- package/dist/sharding/thread.d.ts +30 -0
- package/dist/sharding/transport.d.ts +6 -5
- package/dist/sharding/worker.d.ts +11 -1
- package/dist/structures/base.d.ts +16 -5
- package/dist/structures/index.d.ts +1 -1
- package/dist/structures/index.js +57 -91
- package/dist/structures/index.js.map +10 -18
- package/dist/structures/options.d.ts +3 -2
- package/dist/structures/permissions.d.ts +409 -0
- package/dist/structures/resources.d.ts +4 -1
- package/dist/types/gateway.d.ts +4 -0
- package/dist/types/index.d.ts +14 -4
- package/dist/types/index.js.map +3 -3
- package/dist/utils/args.d.ts +3 -1
- package/dist/utils/index.d.ts +6 -1
- package/dist/utils/index.js +17 -10
- package/dist/utils/index.js.map +4 -4
- package/dist/voice/index.d.ts +7 -1
- package/dist/voice/index.js +33 -10
- package/dist/voice/index.js.map +3 -3
- package/dist/ws/index.d.ts +2 -0
- package/dist/ws/index.js +32 -4
- package/dist/ws/index.js.map +5 -5
- package/package.json +21 -17
|
@@ -1,404 +1,5 @@
|
|
|
1
|
-
/** Permission overwrite target types. */
|
|
2
|
-
export declare enum PermissionOverwriteEnum {
|
|
3
|
-
Role = 0,
|
|
4
|
-
Member = 1
|
|
5
|
-
}
|
|
6
|
-
/** Lunibee idiomatic camelCase permission bitflags. */
|
|
7
|
-
export declare const Permission: {
|
|
8
|
-
readonly createInstantInvite: bigint;
|
|
9
|
-
readonly kickMembers: bigint;
|
|
10
|
-
readonly banMembers: bigint;
|
|
11
|
-
readonly administrator: bigint;
|
|
12
|
-
readonly manageChannels: bigint;
|
|
13
|
-
readonly manageGuild: bigint;
|
|
14
|
-
readonly addReactions: bigint;
|
|
15
|
-
readonly viewAuditLog: bigint;
|
|
16
|
-
readonly prioritySpeaker: bigint;
|
|
17
|
-
readonly stream: bigint;
|
|
18
|
-
readonly viewChannel: bigint;
|
|
19
|
-
readonly sendMessages: bigint;
|
|
20
|
-
readonly sendTTSMessages: bigint;
|
|
21
|
-
readonly manageMessages: bigint;
|
|
22
|
-
readonly embedLinks: bigint;
|
|
23
|
-
readonly attachFiles: bigint;
|
|
24
|
-
readonly readMessageHistory: bigint;
|
|
25
|
-
readonly mentionEveryone: bigint;
|
|
26
|
-
readonly useExternalEmojis: bigint;
|
|
27
|
-
readonly viewGuildInsights: bigint;
|
|
28
|
-
readonly connect: bigint;
|
|
29
|
-
readonly speak: bigint;
|
|
30
|
-
readonly muteMembers: bigint;
|
|
31
|
-
readonly deafenMembers: bigint;
|
|
32
|
-
readonly moveMembers: bigint;
|
|
33
|
-
readonly useVAD: bigint;
|
|
34
|
-
readonly changeNickname: bigint;
|
|
35
|
-
readonly manageNicknames: bigint;
|
|
36
|
-
readonly manageRoles: bigint;
|
|
37
|
-
readonly manageWebhooks: bigint;
|
|
38
|
-
readonly manageGuildExpressions: bigint;
|
|
39
|
-
readonly useApplicationCommands: bigint;
|
|
40
|
-
readonly requestToSpeak: bigint;
|
|
41
|
-
readonly manageEvents: bigint;
|
|
42
|
-
readonly manageThreads: bigint;
|
|
43
|
-
readonly createPublicThreads: bigint;
|
|
44
|
-
readonly createPrivateThreads: bigint;
|
|
45
|
-
readonly useExternalStickers: bigint;
|
|
46
|
-
readonly sendMessagesInThreads: bigint;
|
|
47
|
-
readonly useEmbeddedActivities: bigint;
|
|
48
|
-
readonly moderateMembers: bigint;
|
|
49
|
-
readonly viewCreatorMonetizationAnalytics: bigint;
|
|
50
|
-
readonly useSoundboard: bigint;
|
|
51
|
-
readonly createGuildExpressions: bigint;
|
|
52
|
-
readonly createEvents: bigint;
|
|
53
|
-
readonly useExternalSounds: bigint;
|
|
54
|
-
readonly sendVoiceMessages: bigint;
|
|
55
|
-
readonly setVoiceChannelStatus: bigint;
|
|
56
|
-
readonly sendPolls: bigint;
|
|
57
|
-
readonly useExternalApps: bigint;
|
|
58
|
-
readonly pinMessages: bigint;
|
|
59
|
-
readonly bypassSlowmode: bigint;
|
|
60
|
-
};
|
|
61
|
-
/** Canonical PascalCase permission constants. */
|
|
62
|
-
export declare const Permissions: {
|
|
63
|
-
readonly CreateInstantInvite: bigint;
|
|
64
|
-
readonly KickMembers: bigint;
|
|
65
|
-
readonly BanMembers: bigint;
|
|
66
|
-
readonly Administrator: bigint;
|
|
67
|
-
readonly ManageChannels: bigint;
|
|
68
|
-
readonly ManageGuild: bigint;
|
|
69
|
-
readonly AddReactions: bigint;
|
|
70
|
-
readonly ViewAuditLog: bigint;
|
|
71
|
-
readonly PrioritySpeaker: bigint;
|
|
72
|
-
readonly Stream: bigint;
|
|
73
|
-
readonly ViewChannel: bigint;
|
|
74
|
-
readonly SendMessages: bigint;
|
|
75
|
-
readonly SendTTSMessages: bigint;
|
|
76
|
-
readonly ManageMessages: bigint;
|
|
77
|
-
readonly EmbedLinks: bigint;
|
|
78
|
-
readonly AttachFiles: bigint;
|
|
79
|
-
readonly ReadMessageHistory: bigint;
|
|
80
|
-
readonly MentionEveryone: bigint;
|
|
81
|
-
readonly UseExternalEmojis: bigint;
|
|
82
|
-
readonly ViewGuildInsights: bigint;
|
|
83
|
-
readonly Connect: bigint;
|
|
84
|
-
readonly Speak: bigint;
|
|
85
|
-
readonly MuteMembers: bigint;
|
|
86
|
-
readonly DeafenMembers: bigint;
|
|
87
|
-
readonly MoveMembers: bigint;
|
|
88
|
-
readonly UseVAD: bigint;
|
|
89
|
-
readonly ChangeNickname: bigint;
|
|
90
|
-
readonly ManageNicknames: bigint;
|
|
91
|
-
readonly ManageRoles: bigint;
|
|
92
|
-
readonly ManageWebhooks: bigint;
|
|
93
|
-
readonly ManageGuildExpressions: bigint;
|
|
94
|
-
readonly UseApplicationCommands: bigint;
|
|
95
|
-
readonly RequestToSpeak: bigint;
|
|
96
|
-
readonly ManageEvents: bigint;
|
|
97
|
-
readonly ManageThreads: bigint;
|
|
98
|
-
readonly CreatePublicThreads: bigint;
|
|
99
|
-
readonly CreatePrivateThreads: bigint;
|
|
100
|
-
readonly UseExternalStickers: bigint;
|
|
101
|
-
readonly SendMessagesInThreads: bigint;
|
|
102
|
-
readonly UseEmbeddedActivities: bigint;
|
|
103
|
-
readonly ModerateMembers: bigint;
|
|
104
|
-
readonly ViewCreatorMonetizationAnalytics: bigint;
|
|
105
|
-
readonly UseSoundboard: bigint;
|
|
106
|
-
readonly CreateGuildExpressions: bigint;
|
|
107
|
-
readonly CreateEvents: bigint;
|
|
108
|
-
readonly UseExternalSounds: bigint;
|
|
109
|
-
readonly SendVoiceMessages: bigint;
|
|
110
|
-
readonly SetVoiceChannelStatus: bigint;
|
|
111
|
-
readonly SendPolls: bigint;
|
|
112
|
-
readonly UseExternalApps: bigint;
|
|
113
|
-
readonly PinMessages: bigint;
|
|
114
|
-
readonly BypassSlowmode: bigint;
|
|
115
|
-
};
|
|
116
1
|
/**
|
|
117
|
-
* Permission
|
|
118
|
-
*
|
|
119
|
-
* (`Flags.A | Flags.B`) OR-s the bits instead of concatenating strings.
|
|
120
|
-
*
|
|
121
|
-
* The same object as {@link Permissions}, under the discord.js name. It is a
|
|
122
|
-
* `const` object rather than a TS `enum` because enums cannot hold bigint
|
|
123
|
-
* members; the same-named union type below preserves usage as a type.
|
|
2
|
+
* Permission bits and math live in `@lunibee/structures`, which needs them at
|
|
3
|
+
* runtime (member and role permissions); they are re-exported here unchanged.
|
|
124
4
|
*/
|
|
125
|
-
export
|
|
126
|
-
readonly CreateInstantInvite: bigint;
|
|
127
|
-
readonly KickMembers: bigint;
|
|
128
|
-
readonly BanMembers: bigint;
|
|
129
|
-
readonly Administrator: bigint;
|
|
130
|
-
readonly ManageChannels: bigint;
|
|
131
|
-
readonly ManageGuild: bigint;
|
|
132
|
-
readonly AddReactions: bigint;
|
|
133
|
-
readonly ViewAuditLog: bigint;
|
|
134
|
-
readonly PrioritySpeaker: bigint;
|
|
135
|
-
readonly Stream: bigint;
|
|
136
|
-
readonly ViewChannel: bigint;
|
|
137
|
-
readonly SendMessages: bigint;
|
|
138
|
-
readonly SendTTSMessages: bigint;
|
|
139
|
-
readonly ManageMessages: bigint;
|
|
140
|
-
readonly EmbedLinks: bigint;
|
|
141
|
-
readonly AttachFiles: bigint;
|
|
142
|
-
readonly ReadMessageHistory: bigint;
|
|
143
|
-
readonly MentionEveryone: bigint;
|
|
144
|
-
readonly UseExternalEmojis: bigint;
|
|
145
|
-
readonly ViewGuildInsights: bigint;
|
|
146
|
-
readonly Connect: bigint;
|
|
147
|
-
readonly Speak: bigint;
|
|
148
|
-
readonly MuteMembers: bigint;
|
|
149
|
-
readonly DeafenMembers: bigint;
|
|
150
|
-
readonly MoveMembers: bigint;
|
|
151
|
-
readonly UseVAD: bigint;
|
|
152
|
-
readonly ChangeNickname: bigint;
|
|
153
|
-
readonly ManageNicknames: bigint;
|
|
154
|
-
readonly ManageRoles: bigint;
|
|
155
|
-
readonly ManageWebhooks: bigint;
|
|
156
|
-
readonly ManageGuildExpressions: bigint;
|
|
157
|
-
readonly UseApplicationCommands: bigint;
|
|
158
|
-
readonly RequestToSpeak: bigint;
|
|
159
|
-
readonly ManageEvents: bigint;
|
|
160
|
-
readonly ManageThreads: bigint;
|
|
161
|
-
readonly CreatePublicThreads: bigint;
|
|
162
|
-
readonly CreatePrivateThreads: bigint;
|
|
163
|
-
readonly UseExternalStickers: bigint;
|
|
164
|
-
readonly SendMessagesInThreads: bigint;
|
|
165
|
-
readonly UseEmbeddedActivities: bigint;
|
|
166
|
-
readonly ModerateMembers: bigint;
|
|
167
|
-
readonly ViewCreatorMonetizationAnalytics: bigint;
|
|
168
|
-
readonly UseSoundboard: bigint;
|
|
169
|
-
readonly CreateGuildExpressions: bigint;
|
|
170
|
-
readonly CreateEvents: bigint;
|
|
171
|
-
readonly UseExternalSounds: bigint;
|
|
172
|
-
readonly SendVoiceMessages: bigint;
|
|
173
|
-
readonly SetVoiceChannelStatus: bigint;
|
|
174
|
-
readonly SendPolls: bigint;
|
|
175
|
-
readonly UseExternalApps: bigint;
|
|
176
|
-
readonly PinMessages: bigint;
|
|
177
|
-
readonly BypassSlowmode: bigint;
|
|
178
|
-
};
|
|
179
|
-
/** Union of {@link PermissionFlagsBits} values (all bigint). */
|
|
180
|
-
export type PermissionFlagsBits = (typeof PermissionFlagsBits)[keyof typeof PermissionFlagsBits];
|
|
181
|
-
export type PermissionName = keyof typeof Permission | keyof typeof Permissions | keyof typeof PermissionFlagsBits;
|
|
182
|
-
export type PermissionResolvable = bigint | number | string | PermissionName | PermissionFlagsBits | PermissionSet | PermissionResolvable[];
|
|
183
|
-
/** Immutable permission bitfield with direct boolean getters. */
|
|
184
|
-
export declare class PermissionSet {
|
|
185
|
-
#private;
|
|
186
|
-
/** Permission bitfield. */
|
|
187
|
-
readonly bitfield: bigint;
|
|
188
|
-
/** Creates a permission set. @param value Initial permission bitfield or array of permissions. @throws {RangeError} If the value is negative. @throws {TypeError} If the value is not a valid integer. */
|
|
189
|
-
constructor(value?: PermissionResolvable);
|
|
190
|
-
get createInstantInvite(): boolean;
|
|
191
|
-
get kickMembers(): boolean;
|
|
192
|
-
get banMembers(): boolean;
|
|
193
|
-
get administrator(): boolean;
|
|
194
|
-
get manageChannels(): boolean;
|
|
195
|
-
get manageGuild(): boolean;
|
|
196
|
-
get addReactions(): boolean;
|
|
197
|
-
get viewAuditLog(): boolean;
|
|
198
|
-
get prioritySpeaker(): boolean;
|
|
199
|
-
get stream(): boolean;
|
|
200
|
-
get viewChannel(): boolean;
|
|
201
|
-
get sendMessages(): boolean;
|
|
202
|
-
get sendTTSMessages(): boolean;
|
|
203
|
-
get manageMessages(): boolean;
|
|
204
|
-
get embedLinks(): boolean;
|
|
205
|
-
get attachFiles(): boolean;
|
|
206
|
-
get readMessageHistory(): boolean;
|
|
207
|
-
get mentionEveryone(): boolean;
|
|
208
|
-
get useExternalEmojis(): boolean;
|
|
209
|
-
get viewGuildInsights(): boolean;
|
|
210
|
-
get connect(): boolean;
|
|
211
|
-
get speak(): boolean;
|
|
212
|
-
get muteMembers(): boolean;
|
|
213
|
-
get deafenMembers(): boolean;
|
|
214
|
-
get moveMembers(): boolean;
|
|
215
|
-
get useVAD(): boolean;
|
|
216
|
-
get changeNickname(): boolean;
|
|
217
|
-
get manageNicknames(): boolean;
|
|
218
|
-
get manageRoles(): boolean;
|
|
219
|
-
get manageWebhooks(): boolean;
|
|
220
|
-
get manageGuildExpressions(): boolean;
|
|
221
|
-
get useApplicationCommands(): boolean;
|
|
222
|
-
get requestToSpeak(): boolean;
|
|
223
|
-
get manageEvents(): boolean;
|
|
224
|
-
get manageThreads(): boolean;
|
|
225
|
-
get createPublicThreads(): boolean;
|
|
226
|
-
get createPrivateThreads(): boolean;
|
|
227
|
-
get useExternalStickers(): boolean;
|
|
228
|
-
get sendMessagesInThreads(): boolean;
|
|
229
|
-
get useEmbeddedActivities(): boolean;
|
|
230
|
-
get moderateMembers(): boolean;
|
|
231
|
-
get viewCreatorMonetizationAnalytics(): boolean;
|
|
232
|
-
get useSoundboard(): boolean;
|
|
233
|
-
get createGuildExpressions(): boolean;
|
|
234
|
-
get createEvents(): boolean;
|
|
235
|
-
get useExternalSounds(): boolean;
|
|
236
|
-
get sendVoiceMessages(): boolean;
|
|
237
|
-
get sendPolls(): boolean;
|
|
238
|
-
get useExternalApps(): boolean;
|
|
239
|
-
/** Checks whether all supplied permissions are present (AND). @param permissions Permission names or raw bits. @returns True when every requested permission is present. */
|
|
240
|
-
has(...permissions: PermissionResolvable[]): boolean;
|
|
241
|
-
/** Checks whether any supplied permission is present (OR). @param permissions Permission names or raw bits. @returns True when at least one requested permission is present. */
|
|
242
|
-
any(...permissions: PermissionResolvable[]): boolean;
|
|
243
|
-
/** Returns the known permission names from `permissions` that this set lacks. @param permissions Permission names or raw bits. */
|
|
244
|
-
missing(...permissions: PermissionResolvable[]): PermissionName[];
|
|
245
|
-
/** Returns a new set with permissions added. @param permissions Permission names or raw bits. @returns A new permission set. */
|
|
246
|
-
add(...permissions: PermissionResolvable[]): PermissionSet;
|
|
247
|
-
/** Returns a new set with permissions removed. @param permissions Permission names or raw bits. @returns A new permission set. */
|
|
248
|
-
remove(...permissions: PermissionResolvable[]): PermissionSet;
|
|
249
|
-
/** Checks equality with another permission set or raw bitfield. @param other Permission set or raw bitfield. @returns True when both values are equal. */
|
|
250
|
-
equals(other: PermissionSet | bigint | number | string): boolean;
|
|
251
|
-
/** Returns the decimal permission representation. @returns Decimal permission bitfield. */
|
|
252
|
-
toString(): string;
|
|
253
|
-
/** Returns known permission names contained in this set. @returns Names of all enabled known permissions. */
|
|
254
|
-
toArray(): PermissionName[];
|
|
255
|
-
}
|
|
256
|
-
/** Permissions bitfield alias. */
|
|
257
|
-
export declare class PermissionsBitField extends PermissionSet {
|
|
258
|
-
/** Permission flags bits enum. */
|
|
259
|
-
static readonly Flags: {
|
|
260
|
-
readonly CreateInstantInvite: bigint;
|
|
261
|
-
readonly KickMembers: bigint;
|
|
262
|
-
readonly BanMembers: bigint;
|
|
263
|
-
readonly Administrator: bigint;
|
|
264
|
-
readonly ManageChannels: bigint;
|
|
265
|
-
readonly ManageGuild: bigint;
|
|
266
|
-
readonly AddReactions: bigint;
|
|
267
|
-
readonly ViewAuditLog: bigint;
|
|
268
|
-
readonly PrioritySpeaker: bigint;
|
|
269
|
-
readonly Stream: bigint;
|
|
270
|
-
readonly ViewChannel: bigint;
|
|
271
|
-
readonly SendMessages: bigint;
|
|
272
|
-
readonly SendTTSMessages: bigint;
|
|
273
|
-
readonly ManageMessages: bigint;
|
|
274
|
-
readonly EmbedLinks: bigint;
|
|
275
|
-
readonly AttachFiles: bigint;
|
|
276
|
-
readonly ReadMessageHistory: bigint;
|
|
277
|
-
readonly MentionEveryone: bigint;
|
|
278
|
-
readonly UseExternalEmojis: bigint;
|
|
279
|
-
readonly ViewGuildInsights: bigint;
|
|
280
|
-
readonly Connect: bigint;
|
|
281
|
-
readonly Speak: bigint;
|
|
282
|
-
readonly MuteMembers: bigint;
|
|
283
|
-
readonly DeafenMembers: bigint;
|
|
284
|
-
readonly MoveMembers: bigint;
|
|
285
|
-
readonly UseVAD: bigint;
|
|
286
|
-
readonly ChangeNickname: bigint;
|
|
287
|
-
readonly ManageNicknames: bigint;
|
|
288
|
-
readonly ManageRoles: bigint;
|
|
289
|
-
readonly ManageWebhooks: bigint;
|
|
290
|
-
readonly ManageGuildExpressions: bigint;
|
|
291
|
-
readonly UseApplicationCommands: bigint;
|
|
292
|
-
readonly RequestToSpeak: bigint;
|
|
293
|
-
readonly ManageEvents: bigint;
|
|
294
|
-
readonly ManageThreads: bigint;
|
|
295
|
-
readonly CreatePublicThreads: bigint;
|
|
296
|
-
readonly CreatePrivateThreads: bigint;
|
|
297
|
-
readonly UseExternalStickers: bigint;
|
|
298
|
-
readonly SendMessagesInThreads: bigint;
|
|
299
|
-
readonly UseEmbeddedActivities: bigint;
|
|
300
|
-
readonly ModerateMembers: bigint;
|
|
301
|
-
readonly ViewCreatorMonetizationAnalytics: bigint;
|
|
302
|
-
readonly UseSoundboard: bigint;
|
|
303
|
-
readonly CreateGuildExpressions: bigint;
|
|
304
|
-
readonly CreateEvents: bigint;
|
|
305
|
-
readonly UseExternalSounds: bigint;
|
|
306
|
-
readonly SendVoiceMessages: bigint;
|
|
307
|
-
readonly SetVoiceChannelStatus: bigint;
|
|
308
|
-
readonly SendPolls: bigint;
|
|
309
|
-
readonly UseExternalApps: bigint;
|
|
310
|
-
readonly PinMessages: bigint;
|
|
311
|
-
readonly BypassSlowmode: bigint;
|
|
312
|
-
};
|
|
313
|
-
/** Permission flags constants. */
|
|
314
|
-
static readonly All: {
|
|
315
|
-
readonly createInstantInvite: bigint;
|
|
316
|
-
readonly kickMembers: bigint;
|
|
317
|
-
readonly banMembers: bigint;
|
|
318
|
-
readonly administrator: bigint;
|
|
319
|
-
readonly manageChannels: bigint;
|
|
320
|
-
readonly manageGuild: bigint;
|
|
321
|
-
readonly addReactions: bigint;
|
|
322
|
-
readonly viewAuditLog: bigint;
|
|
323
|
-
readonly prioritySpeaker: bigint;
|
|
324
|
-
readonly stream: bigint;
|
|
325
|
-
readonly viewChannel: bigint;
|
|
326
|
-
readonly sendMessages: bigint;
|
|
327
|
-
readonly sendTTSMessages: bigint;
|
|
328
|
-
readonly manageMessages: bigint;
|
|
329
|
-
readonly embedLinks: bigint;
|
|
330
|
-
readonly attachFiles: bigint;
|
|
331
|
-
readonly readMessageHistory: bigint;
|
|
332
|
-
readonly mentionEveryone: bigint;
|
|
333
|
-
readonly useExternalEmojis: bigint;
|
|
334
|
-
readonly viewGuildInsights: bigint;
|
|
335
|
-
readonly connect: bigint;
|
|
336
|
-
readonly speak: bigint;
|
|
337
|
-
readonly muteMembers: bigint;
|
|
338
|
-
readonly deafenMembers: bigint;
|
|
339
|
-
readonly moveMembers: bigint;
|
|
340
|
-
readonly useVAD: bigint;
|
|
341
|
-
readonly changeNickname: bigint;
|
|
342
|
-
readonly manageNicknames: bigint;
|
|
343
|
-
readonly manageRoles: bigint;
|
|
344
|
-
readonly manageWebhooks: bigint;
|
|
345
|
-
readonly manageGuildExpressions: bigint;
|
|
346
|
-
readonly useApplicationCommands: bigint;
|
|
347
|
-
readonly requestToSpeak: bigint;
|
|
348
|
-
readonly manageEvents: bigint;
|
|
349
|
-
readonly manageThreads: bigint;
|
|
350
|
-
readonly createPublicThreads: bigint;
|
|
351
|
-
readonly createPrivateThreads: bigint;
|
|
352
|
-
readonly useExternalStickers: bigint;
|
|
353
|
-
readonly sendMessagesInThreads: bigint;
|
|
354
|
-
readonly useEmbeddedActivities: bigint;
|
|
355
|
-
readonly moderateMembers: bigint;
|
|
356
|
-
readonly viewCreatorMonetizationAnalytics: bigint;
|
|
357
|
-
readonly useSoundboard: bigint;
|
|
358
|
-
readonly createGuildExpressions: bigint;
|
|
359
|
-
readonly createEvents: bigint;
|
|
360
|
-
readonly useExternalSounds: bigint;
|
|
361
|
-
readonly sendVoiceMessages: bigint;
|
|
362
|
-
readonly setVoiceChannelStatus: bigint;
|
|
363
|
-
readonly sendPolls: bigint;
|
|
364
|
-
readonly useExternalApps: bigint;
|
|
365
|
-
readonly pinMessages: bigint;
|
|
366
|
-
readonly bypassSlowmode: bigint;
|
|
367
|
-
};
|
|
368
|
-
/** Creates a permissions bitfield. @param value Initial permission bitfield or array of permissions. */
|
|
369
|
-
constructor(value?: PermissionResolvable);
|
|
370
|
-
}
|
|
371
|
-
/** A role as needed for permission resolution. */
|
|
372
|
-
export interface PermissionRole {
|
|
373
|
-
id: string;
|
|
374
|
-
permissions: PermissionResolvable;
|
|
375
|
-
}
|
|
376
|
-
/** A channel permission overwrite (Discord's `permission_overwrites` entry). */
|
|
377
|
-
export interface PermissionOverwrite {
|
|
378
|
-
id: string;
|
|
379
|
-
type: PermissionOverwriteEnum | number;
|
|
380
|
-
allow: PermissionResolvable;
|
|
381
|
-
deny: PermissionResolvable;
|
|
382
|
-
}
|
|
383
|
-
/** Everything needed to resolve a member's permissions. */
|
|
384
|
-
export interface PermissionContext {
|
|
385
|
-
guildId: string;
|
|
386
|
-
/** Guild owner ID; the owner has every permission. */
|
|
387
|
-
ownerId?: string;
|
|
388
|
-
memberId: string;
|
|
389
|
-
memberRoleIds: readonly string[];
|
|
390
|
-
/** Guild roles, including `@everyone` (whose ID is the guild ID). */
|
|
391
|
-
roles: readonly PermissionRole[];
|
|
392
|
-
/** Channel overwrites; omit for guild-level permissions. */
|
|
393
|
-
overwrites?: readonly PermissionOverwrite[];
|
|
394
|
-
/** When the member's timeout ends; while it is in the future the member keeps only View Channel and Read Message History. */
|
|
395
|
-
timedOutUntil?: Date | number | null;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Resolves a member's effective permissions the way Discord does: base
|
|
399
|
-
* permissions from `@everyone` and the member's roles (owner and
|
|
400
|
-
* administrator get everything), then the channel's `@everyone` overwrite,
|
|
401
|
-
* the combined role overwrites, and finally the member overwrite. A member
|
|
402
|
-
* whose timeout has not ended keeps only View Channel and Read Message History.
|
|
403
|
-
*/
|
|
404
|
-
export declare function computePermissions(context: PermissionContext): PermissionSet;
|
|
5
|
+
export { Permission, Permissions, PermissionFlagsBits, PermissionSet, PermissionsBitField, PermissionOverwriteEnum, computePermissions, type PermissionContext, type PermissionOverwrite, type PermissionRole, type PermissionName, type PermissionResolvable, } from "@lunibee/structures";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shared cache in Redis, beside the in-memory one.
|
|
3
|
+
*
|
|
4
|
+
* The in-memory cache of each process holds the guilds its shards receive.
|
|
5
|
+
* `RedisCache` mirrors the same Gateway events into Redis as raw Discord
|
|
6
|
+
* payloads, so any process — another cluster, a dashboard, a worker without
|
|
7
|
+
* a Gateway — can read any guild. It never replaces the synchronous cache.
|
|
8
|
+
*/
|
|
9
|
+
import type { RedisCommandClient } from "@lunibee/collection";
|
|
10
|
+
export type { RedisCommandClient };
|
|
11
|
+
/** What `attach()` listens to: a `Client` (its `raw` event) or a `Gateway` (`RAW`). */
|
|
12
|
+
export interface RawDispatchSource {
|
|
13
|
+
on(event: any, listener: any): unknown;
|
|
14
|
+
off(event: any, listener: any): unknown;
|
|
15
|
+
}
|
|
16
|
+
/** Options for {@link RedisCache}. */
|
|
17
|
+
export interface RedisCacheOptions {
|
|
18
|
+
/** The Redis client. `Bun.RedisClient` works as it is; for ioredis pass `{ send: (c, a) => redis.call(c, ...a) }`. */
|
|
19
|
+
client: RedisCommandClient;
|
|
20
|
+
/** Key prefix. Default `"lunibee:cache:"`; keys are versioned under it (`…v1:…`). */
|
|
21
|
+
prefix?: string;
|
|
22
|
+
/** Store members and their users. Default `true`. */
|
|
23
|
+
members?: boolean;
|
|
24
|
+
/** Expire every key this many seconds after its last write. Default: never. */
|
|
25
|
+
ttlSeconds?: number;
|
|
26
|
+
/** Called when a write fails. Writes never throw into the Gateway. */
|
|
27
|
+
onError?: (operation: string, error: unknown) => void;
|
|
28
|
+
}
|
|
29
|
+
/** Health of a {@link RedisCache}. */
|
|
30
|
+
export interface RedisCacheDiagnostics {
|
|
31
|
+
/** Events written. */
|
|
32
|
+
writes: number;
|
|
33
|
+
/** Writes that failed. */
|
|
34
|
+
failures: number;
|
|
35
|
+
/** Events waiting to be written. */
|
|
36
|
+
pending: number;
|
|
37
|
+
}
|
|
38
|
+
type Payload = Record<string, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* A Redis mirror of guilds, channels, roles, members and users.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* const shared = new RedisCache({ client: new Bun.RedisClient(process.env.REDIS_URL) });
|
|
44
|
+
* shared.attach(client); // or each shard's Gateway
|
|
45
|
+
* const guild = await shared.guild(id); // from any process
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Writes for one guild are applied in Gateway order; a failed write is
|
|
49
|
+
* reported through `onError` and never reaches the Gateway. Reads throw on a
|
|
50
|
+
* Redis error. Values are raw Discord payloads (`APIGuild`-shaped JSON).
|
|
51
|
+
*/
|
|
52
|
+
export declare class RedisCache {
|
|
53
|
+
#private;
|
|
54
|
+
constructor(options: RedisCacheOptions);
|
|
55
|
+
/**
|
|
56
|
+
* Mirrors the dispatches of a `Client` (its `raw` event) or of one
|
|
57
|
+
* `Gateway` (`RAW`). Attach each shard's Gateway, or the client once.
|
|
58
|
+
*/
|
|
59
|
+
attach(source: RawDispatchSource): this;
|
|
60
|
+
/** Stops mirroring `source` (or every source). */
|
|
61
|
+
detach(source?: RawDispatchSource): this;
|
|
62
|
+
/** Resolves when every write queued so far has been applied (or failed). */
|
|
63
|
+
flush(): Promise<void>;
|
|
64
|
+
diagnostics(): RedisCacheDiagnostics;
|
|
65
|
+
/**
|
|
66
|
+
* Applies one Gateway dispatch. `attach()` calls it; call it yourself to
|
|
67
|
+
* feed events from elsewhere (an IPC relay, a replay).
|
|
68
|
+
*/
|
|
69
|
+
handle(event: string, data: unknown): void;
|
|
70
|
+
/** The guild document (without its channels, roles and members). */
|
|
71
|
+
guild<T extends object = Payload>(guildId: string): Promise<T | undefined>;
|
|
72
|
+
/** Ids of every guild in the cache. */
|
|
73
|
+
guildIds(): Promise<string[]>;
|
|
74
|
+
/** A channel or thread, with its `guild_id`. */
|
|
75
|
+
channel<T extends object = Payload>(channelId: string): Promise<T | undefined>;
|
|
76
|
+
/** Every channel and thread of a guild. */
|
|
77
|
+
channels<T extends object = Payload>(guildId: string): Promise<T[]>;
|
|
78
|
+
role<T extends object = Payload>(guildId: string, roleId: string): Promise<T | undefined>;
|
|
79
|
+
roles<T extends object = Payload>(guildId: string): Promise<T[]>;
|
|
80
|
+
user<T extends object = Payload>(userId: string): Promise<T | undefined>;
|
|
81
|
+
/** A member, with its `user` attached. */
|
|
82
|
+
member<T extends object = Payload>(guildId: string, userId: string): Promise<T | undefined>;
|
|
83
|
+
/** Every cached member of a guild, with users. Large guilds: mind the size. */
|
|
84
|
+
members<T extends object = Payload>(guildId: string): Promise<T[]>;
|
|
85
|
+
}
|
|
@@ -46,5 +46,9 @@ export declare function subtext(text: string): string;
|
|
|
46
46
|
export declare function orderedList(...items: string[]): string;
|
|
47
47
|
/** Creates an unordered bullet list from items. */
|
|
48
48
|
export declare function bulletList(...items: string[]): string;
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Escapes the inline Discord markdown characters `\ * _ ` ~ | >`. It does not
|
|
51
|
+
* neutralise headings, lists or `[label](url)` links: pair it with
|
|
52
|
+
* `allowedMentions` and never rely on it to sanitise untrusted text.
|
|
53
|
+
*/
|
|
50
54
|
export declare function escapeMarkdown(value: string): string;
|
package/dist/formatters/index.js
CHANGED
|
@@ -14,6 +14,8 @@ function timestamp(unixSeconds, style) {
|
|
|
14
14
|
throw new TypeError("Timestamp must be a finite Unix timestamp.");
|
|
15
15
|
if (style !== undefined && !/^[tTdDfFR]$/.test(style))
|
|
16
16
|
throw new RangeError("Invalid Discord timestamp style.");
|
|
17
|
+
if (!Number.isSafeInteger(Math.floor(unixSeconds)))
|
|
18
|
+
throw new RangeError("Timestamp is out of range.");
|
|
17
19
|
return `<t:${Math.floor(unixSeconds)}${style ? `:${style}` : ""}>`;
|
|
18
20
|
}
|
|
19
21
|
function bold(text) {
|
|
@@ -38,16 +40,18 @@ function inlineCode(text) {
|
|
|
38
40
|
return `\`${text}\``;
|
|
39
41
|
}
|
|
40
42
|
function codeBlock(text, language = "") {
|
|
41
|
-
const safe = text.replace(
|
|
43
|
+
const safe = text.replace(/`(?=`)/g, "`\u200B");
|
|
42
44
|
const lang = language.replace(/[^\w+#.-]/g, "");
|
|
43
45
|
return `\`\`\`${lang}
|
|
44
46
|
${safe}
|
|
45
47
|
\`\`\``;
|
|
46
48
|
}
|
|
47
49
|
function link(label, url, title) {
|
|
50
|
+
if (!/^(?:https?|discord):\/\//i.test(url))
|
|
51
|
+
throw new TypeError("link() only accepts http, https or discord URLs.");
|
|
48
52
|
const text = label.replace(/[[\]\\]/g, "\\$&").replace(/\n/g, " ");
|
|
49
53
|
const target = url.replace(/[()\s"]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`);
|
|
50
|
-
const titlePart = title ? ` "${title.replace(/["\n]/g, "")}"` : "";
|
|
54
|
+
const titlePart = title ? ` "${title.replace(/["\n)]/g, "")}"` : "";
|
|
51
55
|
return `[${text}](${target}${titlePart})`;
|
|
52
56
|
}
|
|
53
57
|
function blockQuote(text) {
|
|
@@ -107,4 +111,4 @@ export {
|
|
|
107
111
|
userMention
|
|
108
112
|
};
|
|
109
113
|
|
|
110
|
-
//# debugId=
|
|
114
|
+
//# debugId=9B1DEB0C74BB980D64756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/formatters/src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// ─── Mentions ──────────────────────────────────────────────────────────────────\n\n/** Creates a user mention from a Discord snowflake. */\nexport function userMention(id: string): string {\n return `<@${validateSnowflake(id, \"User ID\")}>`;\n}\n\n/** Creates a channel mention from a Discord snowflake. */\nexport function channelMention(id: string): string {\n return `<#${validateSnowflake(id, \"Channel ID\")}>`;\n}\n\n/** Creates a role mention from a Discord snowflake. */\nexport function roleMention(id: string): string {\n return `<@&${validateSnowflake(id, \"Role ID\")}>`;\n}\n\n// ─── Timestamps ────────────────────────────────────────────────────────────────\n\n/** Discord timestamp style formats. */\nexport type TimestampStyle = \"t\" | \"T\" | \"d\" | \"D\" | \"f\" | \"F\" | \"R\";\n\n/** Creates a Discord timestamp tag.\n * @param unixSeconds Unix timestamp in seconds.\n * @param style Optional display style: t=short time, T=long time, d=short date, D=long date, f=short datetime, F=long datetime, R=relative.\n */\nexport function timestamp(\n unixSeconds: number,\n style?: TimestampStyle | string,\n): string {\n if (!Number.isFinite(unixSeconds))\n throw new TypeError(\"Timestamp must be a finite Unix timestamp.\");\n if (style !== undefined && !/^[tTdDfFR]$/.test(style))\n throw new RangeError(\"Invalid Discord timestamp style.\");\n return `<t:${Math.floor(unixSeconds)}${style ? `:${style}` : \"\"}>`;\n}\n\n// ─── Markdown ─────────────────────────────────────────────────────────────────\n\n/** Wraps text in Discord bold markdown. */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/** Wraps text in Discord italic markdown. */\nexport function italic(text: string): string {\n return `_${text}_`;\n}\n\n/** Wraps text in Discord underline markdown. */\nexport function underline(text: string): string {\n return `__${text}__`;\n}\n\n/** Wraps text in Discord strikethrough markdown. */\nexport function strikethrough(text: string): string {\n return `~~${text}~~`;\n}\n\n/** Wraps text in a Discord spoiler tag (shown masked until clicked). */\nexport function spoiler(text: string): string {\n return `||${text}||`;\n}\n\n/** Alias for spoiler — hides text until revealed. */\nexport function masked(text: string): string {\n return spoiler(text);\n}\n\n/** Wraps text in Discord inline code. */\nexport function inlineCode(text: string): string {\n return `\\`${text}\\``;\n}\n\n/** Wraps text in a Discord fenced code block.\n * @param text Code content.\n * @param language Optional language identifier for syntax highlighting.\n */\nexport function codeBlock(text: string, language = \"\"): string {\n // A zero-width space between backticks
|
|
5
|
+
"// ─── Mentions ──────────────────────────────────────────────────────────────────\n\n/** Creates a user mention from a Discord snowflake. */\nexport function userMention(id: string): string {\n return `<@${validateSnowflake(id, \"User ID\")}>`;\n}\n\n/** Creates a channel mention from a Discord snowflake. */\nexport function channelMention(id: string): string {\n return `<#${validateSnowflake(id, \"Channel ID\")}>`;\n}\n\n/** Creates a role mention from a Discord snowflake. */\nexport function roleMention(id: string): string {\n return `<@&${validateSnowflake(id, \"Role ID\")}>`;\n}\n\n// ─── Timestamps ────────────────────────────────────────────────────────────────\n\n/** Discord timestamp style formats. */\nexport type TimestampStyle = \"t\" | \"T\" | \"d\" | \"D\" | \"f\" | \"F\" | \"R\";\n\n/** Creates a Discord timestamp tag.\n * @param unixSeconds Unix timestamp in seconds.\n * @param style Optional display style: t=short time, T=long time, d=short date, D=long date, f=short datetime, F=long datetime, R=relative.\n */\nexport function timestamp(\n unixSeconds: number,\n style?: TimestampStyle | string,\n): string {\n if (!Number.isFinite(unixSeconds))\n throw new TypeError(\"Timestamp must be a finite Unix timestamp.\");\n if (style !== undefined && !/^[tTdDfFR]$/.test(style))\n throw new RangeError(\"Invalid Discord timestamp style.\");\n if (!Number.isSafeInteger(Math.floor(unixSeconds)))\n throw new RangeError(\"Timestamp is out of range.\");\n return `<t:${Math.floor(unixSeconds)}${style ? `:${style}` : \"\"}>`;\n}\n\n// ─── Markdown ─────────────────────────────────────────────────────────────────\n\n/** Wraps text in Discord bold markdown. */\nexport function bold(text: string): string {\n return `**${text}**`;\n}\n\n/** Wraps text in Discord italic markdown. */\nexport function italic(text: string): string {\n return `_${text}_`;\n}\n\n/** Wraps text in Discord underline markdown. */\nexport function underline(text: string): string {\n return `__${text}__`;\n}\n\n/** Wraps text in Discord strikethrough markdown. */\nexport function strikethrough(text: string): string {\n return `~~${text}~~`;\n}\n\n/** Wraps text in a Discord spoiler tag (shown masked until clicked). */\nexport function spoiler(text: string): string {\n return `||${text}||`;\n}\n\n/** Alias for spoiler — hides text until revealed. */\nexport function masked(text: string): string {\n return spoiler(text);\n}\n\n/** Wraps text in Discord inline code. */\nexport function inlineCode(text: string): string {\n return `\\`${text}\\``;\n}\n\n/** Wraps text in a Discord fenced code block.\n * @param text Code content.\n * @param language Optional language identifier for syntax highlighting.\n */\nexport function codeBlock(text: string, language = \"\"): string {\n // A zero-width space between every two adjacent backticks: no run of any\n // length (```` included) can then form a closing fence.\n const safe = text.replace(/`(?=`)/g, \"`\\u200b\");\n const lang = language.replace(/[^\\w+#.-]/g, \"\");\n return `\\`\\`\\`${lang}\\n${safe}\\n\\`\\`\\``;\n}\n\n/** Creates a Discord masked hyperlink: [label](url).\n * @param label Display text.\n * @param url Destination URL.\n * @param title Optional hover title.\n */\nexport function link(label: string, url: string, title?: string): string {\n // Brackets in the label and parentheses, quotes or spaces in the URL would\n // otherwise end the link early and let the rest render as a second link.\n if (!/^(?:https?|discord):\\/\\//i.test(url))\n throw new TypeError(\"link() only accepts http, https or discord URLs.\");\n const text = label.replace(/[[\\]\\\\]/g, \"\\\\$&\").replace(/\\n/g, \" \");\n const target = url.replace(\n /[()\\s\"]/g,\n (c) =>\n `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, \"0\")}`,\n );\n const titlePart = title ? ` \"${title.replace(/[\"\\n)]/g, \"\")}\"` : \"\";\n return `[${text}](${target}${titlePart})`;\n}\n\n/** Wraps each line of text in a Discord block quote (> prefix). */\nexport function blockQuote(text: string): string {\n return text\n .split(\"\\n\")\n .map((line) => `> ${line}`)\n .join(\"\\n\");\n}\n\n/** Creates a Discord heading at the given level (1–3). */\nexport function heading(text: string, level: 1 | 2 | 3 = 1): string {\n return `${\"#\".repeat(level)} ${text}`;\n}\n\n/** Wraps text in Discord's subtext markdown (-# prefix). */\nexport function subtext(text: string): string {\n return `-# ${text}`;\n}\n\n/** Creates a numbered ordered list from items. */\nexport function orderedList(...items: string[]): string {\n return items.map((item, i) => `${i + 1}. ${item}`).join(\"\\n\");\n}\n\n/** Creates an unordered bullet list from items. */\nexport function bulletList(...items: string[]): string {\n return items.map((item) => `- ${item}`).join(\"\\n\");\n}\n\n// ─── Utilities ─────────────────────────────────────────────────────────────────\n\n/**\n * Escapes the inline Discord markdown characters `\\ * _ ` ~ | >`. It does not\n * neutralise headings, lists or `[label](url)` links: pair it with\n * `allowedMentions` and never rely on it to sanitise untrusted text.\n */\nexport function escapeMarkdown(value: string): string {\n return value.replace(/[\\\\*_`~|>]/g, \"\\\\$&\");\n}\n\nfunction validateSnowflake(id: string, field: string): string {\n const len = id.length;\n if (len < 1 || len > 20) {\n throw new TypeError(`${field} must be a valid Discord snowflake.`);\n }\n for (let i = 0; i < len; i++) {\n const code = id.charCodeAt(i);\n if (code < 48 || code > 57) {\n throw new TypeError(`${field} must be a valid Discord snowflake.`);\n }\n }\n return id;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;AAGO,SAAS,WAAW,CAAC,IAAoB;AAAA,EAC5C,OAAO,KAAK,kBAAkB,IAAI,SAAS;AAAA;AAIxC,SAAS,cAAc,CAAC,IAAoB;AAAA,EAC/C,OAAO,KAAK,kBAAkB,IAAI,YAAY;AAAA;AAI3C,SAAS,WAAW,CAAC,IAAoB;AAAA,EAC5C,OAAO,MAAM,kBAAkB,IAAI,SAAS;AAAA;AAYzC,SAAS,SAAS,CACrB,aACA,OACM;AAAA,EACN,IAAI,CAAC,OAAO,SAAS,WAAW;AAAA,IAC5B,MAAM,IAAI,UAAU,4CAA4C;AAAA,EACpE,IAAI,UAAU,aAAa,CAAC,cAAc,KAAK,KAAK;AAAA,IAChD,MAAM,IAAI,WAAW,kCAAkC;AAAA,EAC3D,OAAO,MAAM,KAAK,MAAM,WAAW,IAAI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AA,EAChE,OAAO,GAAG,IAAI,OAAO,KAAK,KAAK;AAAA;AAI5B,SAAS,OAAO,CAAC,MAAsB;AAAA,EAC1C,OAAO,MAAM;AAAA;AAIV,SAAS,WAAW,IAAI,OAAyB;AAAA,EACpD,OAAO,MAAM,IAAI,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,MAAM,EAAE,KAAK;AAAA,CAAI;AAAA;AAIzD,SAAS,UAAU,IAAI,OAAyB;AAAA,EACnD,OAAO,MAAM,IAAI,CAAC,SAAS,KAAK,MAAM,EAAE,KAAK;AAAA,CAAI;AAAA;AAU9C,SAAS,cAAc,CAAC,OAAuB;AAAA,EAClD,OAAO,MAAM,QAAQ,eAAe,MAAM;AAAA;AAG9C,SAAS,iBAAiB,CAAC,IAAY,OAAuB;AAAA,EAC1D,MAAM,MAAM,GAAG;AAAA,EACf,IAAI,MAAM,KAAK,MAAM,IAAI;AAAA,IACrB,MAAM,IAAI,UAAU,GAAG,0CAA0C;AAAA,EACrE;AAAA,EACA,SAAS,IAAI,EAAG,IAAI,KAAK,KAAK;AAAA,IAC1B,MAAM,OAAO,GAAG,WAAW,CAAC;AAAA,IAC5B,IAAI,OAAO,MAAM,OAAO,IAAI;AAAA,MACxB,MAAM,IAAI,UAAU,GAAG,0CAA0C;AAAA,IACrE;AAAA,EACJ;AAAA,EACA,OAAO;AAAA;",
|
|
8
|
+
"debugId": "9B1DEB0C74BB980D64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/handlers/index.js
CHANGED
|
@@ -18,8 +18,17 @@ class HandlerRegistry {
|
|
|
18
18
|
return this;
|
|
19
19
|
}
|
|
20
20
|
async dispatch(event, ...args) {
|
|
21
|
+
const errors = [];
|
|
21
22
|
for (const handler of this.#handlers[event] ?? [])
|
|
22
|
-
|
|
23
|
+
try {
|
|
24
|
+
await handler(...args);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
errors.push(error);
|
|
27
|
+
}
|
|
28
|
+
if (errors.length === 1)
|
|
29
|
+
throw errors[0];
|
|
30
|
+
if (errors.length > 1)
|
|
31
|
+
throw new AggregateError(errors, "Several handlers failed.");
|
|
23
32
|
}
|
|
24
33
|
emit(event, ...args) {
|
|
25
34
|
return this.dispatch(event, ...args);
|
|
@@ -29,4 +38,4 @@ export {
|
|
|
29
38
|
HandlerRegistry
|
|
30
39
|
};
|
|
31
40
|
|
|
32
|
-
//# debugId=
|
|
41
|
+
//# debugId=45F209F9FE619D0964756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/handlers/src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/** A typed handler registry for Lunibee events. */\nexport class HandlerRegistry<\n Events extends { [K in keyof Events]: unknown[] },\n> {\n /** Registered event handlers. */\n readonly #handlers: {\n [K in keyof Events]?: Set<(...args: Events[K]) => unknown>;\n } = {};\n /** Registers a handler for an event. @param event Event key. @param handler Handler callback. @returns This registry. */\n public on<K extends keyof Events>(\n event: K,\n handler: (...args: Events[K]) => unknown,\n ): this {\n (this.#handlers[event] ??= new Set()).add(handler);\n return this;\n }\n /** Registers a one-shot handler. @param event Event key. @param handler Handler callback. @returns This registry. */\n public once<K extends keyof Events>(\n event: K,\n handler: (...args: Events[K]) => unknown,\n ): this {\n const wrapped = (...args: Events[K]) => {\n this.off(event, wrapped);\n return handler(...args);\n };\n return this.on(event, wrapped);\n }\n /** Removes a handler. @param event Event key. @param handler Handler callback. @returns This registry. */\n public off<K extends keyof Events>(\n event: K,\n handler: (...args: Events[K]) => unknown,\n ): this {\n this.#handlers[event]?.delete(handler);\n return this;\n }\n /** Dispatches an event to registered handlers. @param event Event key. @param args Event arguments. @returns A promise fulfilled after handlers complete. */\n public async dispatch<K extends keyof Events>(\n event: K,\n ...args: Events[K]\n ): Promise<void> {\n for (const handler of this.#handlers[event] ?? [])\n await handler(...args);\n }\n /** Emits an event using the conventional emitter name. @param event Event key. @param args Event arguments. @returns A promise fulfilled after handlers complete. */\n public emit<K extends keyof Events>(\n event: K,\n ...args: Events[K]\n ): Promise<void> {\n return this.dispatch(event, ...args);\n }\n}\n"
|
|
5
|
+
"/** A typed handler registry for Lunibee events. */\nexport class HandlerRegistry<\n Events extends { [K in keyof Events]: unknown[] },\n> {\n /** Registered event handlers. */\n readonly #handlers: {\n [K in keyof Events]?: Set<(...args: Events[K]) => unknown>;\n } = {};\n /** Registers a handler for an event. @param event Event key. @param handler Handler callback. @returns This registry. */\n public on<K extends keyof Events>(\n event: K,\n handler: (...args: Events[K]) => unknown,\n ): this {\n (this.#handlers[event] ??= new Set()).add(handler);\n return this;\n }\n /** Registers a one-shot handler. @param event Event key. @param handler Handler callback. @returns This registry. */\n public once<K extends keyof Events>(\n event: K,\n handler: (...args: Events[K]) => unknown,\n ): this {\n const wrapped = (...args: Events[K]) => {\n this.off(event, wrapped);\n return handler(...args);\n };\n return this.on(event, wrapped);\n }\n /** Removes a handler. @param event Event key. @param handler Handler callback. @returns This registry. */\n public off<K extends keyof Events>(\n event: K,\n handler: (...args: Events[K]) => unknown,\n ): this {\n this.#handlers[event]?.delete(handler);\n return this;\n }\n /** Dispatches an event to registered handlers. @param event Event key. @param args Event arguments. @returns A promise fulfilled after handlers complete. */\n public async dispatch<K extends keyof Events>(\n event: K,\n ...args: Events[K]\n ): Promise<void> {\n const errors: unknown[] = [];\n for (const handler of this.#handlers[event] ?? [])\n try {\n await handler(...args);\n } catch (error) {\n errors.push(error);\n }\n if (errors.length === 1) throw errors[0];\n if (errors.length > 1)\n throw new AggregateError(errors, \"Several handlers failed.\");\n }\n /** Emits an event using the conventional emitter name. @param event Event key. @param args Event arguments. @returns A promise fulfilled after handlers complete. */\n public emit<K extends keyof Events>(\n event: K,\n ...args: Events[K]\n ): Promise<void> {\n return this.dispatch(event, ...args);\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;AACO,MAAM,gBAEX;AAAA,EAEW,YAEL,CAAC;AAAA,E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