@wolfstar/http-framework 2.3.1 → 3.0.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/LICENSE +201 -0
- package/dist/esm/index.d.ts +88 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +174 -45
- package/dist/esm/index.js.map +1 -1
- package/package.json +67 -68
package/dist/esm/index.js
CHANGED
|
@@ -408,6 +408,120 @@ var StringIdParser = class {
|
|
|
408
408
|
}
|
|
409
409
|
};
|
|
410
410
|
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/lib/types/Enums.ts
|
|
413
|
+
let PluginHook = /* @__PURE__ */ function(PluginHook) {
|
|
414
|
+
PluginHook["PreGenericsInitialization"] = "preGenericsInitialization";
|
|
415
|
+
PluginHook["PreInitialization"] = "preInitialization";
|
|
416
|
+
PluginHook["PostInitialization"] = "postInitialization";
|
|
417
|
+
PluginHook["PreLoad"] = "preLoad";
|
|
418
|
+
PluginHook["PostListen"] = "postListen";
|
|
419
|
+
return PluginHook;
|
|
420
|
+
}({});
|
|
421
|
+
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/lib/plugins/symbols.ts
|
|
424
|
+
const preGenericsInitialization = Symbol("HttpFrameworkPluginsPreGenericsInitialization");
|
|
425
|
+
const preInitialization = Symbol("HttpFrameworkPluginsPreInitialization");
|
|
426
|
+
const postInitialization = Symbol("HttpFrameworkPluginsPostInitialization");
|
|
427
|
+
const preLoad = Symbol("HttpFrameworkPluginsPreLoad");
|
|
428
|
+
const postListen = Symbol("HttpFrameworkPluginsPostListen");
|
|
429
|
+
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
432
|
+
function _typeof(o) {
|
|
433
|
+
"@babel/helpers - typeof";
|
|
434
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
435
|
+
return typeof o;
|
|
436
|
+
} : function(o) {
|
|
437
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
438
|
+
}, _typeof(o);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
443
|
+
function toPrimitive(t, r) {
|
|
444
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
445
|
+
var e = t[Symbol.toPrimitive];
|
|
446
|
+
if (void 0 !== e) {
|
|
447
|
+
var i = e.call(t, r || "default");
|
|
448
|
+
if ("object" != _typeof(i)) return i;
|
|
449
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
450
|
+
}
|
|
451
|
+
return ("string" === r ? String : Number)(t);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
456
|
+
function toPropertyKey(t) {
|
|
457
|
+
var i = toPrimitive(t, "string");
|
|
458
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
463
|
+
function _defineProperty(e, r, t) {
|
|
464
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
465
|
+
value: t,
|
|
466
|
+
enumerable: !0,
|
|
467
|
+
configurable: !0,
|
|
468
|
+
writable: !0
|
|
469
|
+
}) : e[r] = t, e;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
//#endregion
|
|
473
|
+
//#region src/lib/plugins/PluginManager.ts
|
|
474
|
+
var PluginManager = class {
|
|
475
|
+
constructor() {
|
|
476
|
+
_defineProperty(this, "registry", /* @__PURE__ */ new Set());
|
|
477
|
+
}
|
|
478
|
+
registerHook(hook, type, name) {
|
|
479
|
+
if (typeof hook !== "function") throw new TypeError(`The provided hook ${name ? `(${name}) ` : ""}is not a function`);
|
|
480
|
+
this.registry.add({
|
|
481
|
+
hook,
|
|
482
|
+
type,
|
|
483
|
+
name
|
|
484
|
+
});
|
|
485
|
+
return this;
|
|
486
|
+
}
|
|
487
|
+
registerPreGenericsInitializationHook(hook, name) {
|
|
488
|
+
return this.registerHook(hook, "preGenericsInitialization", name);
|
|
489
|
+
}
|
|
490
|
+
registerPreInitializationHook(hook, name) {
|
|
491
|
+
return this.registerHook(hook, "preInitialization", name);
|
|
492
|
+
}
|
|
493
|
+
registerPostInitializationHook(hook, name) {
|
|
494
|
+
return this.registerHook(hook, "postInitialization", name);
|
|
495
|
+
}
|
|
496
|
+
registerPreLoadHook(hook, name) {
|
|
497
|
+
return this.registerHook(hook, "preLoad", name);
|
|
498
|
+
}
|
|
499
|
+
registerPostListenHook(hook, name) {
|
|
500
|
+
return this.registerHook(hook, "postListen", name);
|
|
501
|
+
}
|
|
502
|
+
use(plugin) {
|
|
503
|
+
const possibleSymbolHooks = [
|
|
504
|
+
[preGenericsInitialization, "preGenericsInitialization"],
|
|
505
|
+
[preInitialization, "preInitialization"],
|
|
506
|
+
[postInitialization, "postInitialization"],
|
|
507
|
+
[preLoad, "preLoad"],
|
|
508
|
+
[postListen, "postListen"]
|
|
509
|
+
];
|
|
510
|
+
for (const [hookSymbol, hookType] of possibleSymbolHooks) {
|
|
511
|
+
const hook = Reflect.get(plugin, hookSymbol);
|
|
512
|
+
if (typeof hook !== "function") continue;
|
|
513
|
+
this.registerHook(hook, hookType, plugin.name);
|
|
514
|
+
}
|
|
515
|
+
return this;
|
|
516
|
+
}
|
|
517
|
+
*values(hook) {
|
|
518
|
+
for (const plugin of this.registry) {
|
|
519
|
+
if (hook && plugin.type !== hook) continue;
|
|
520
|
+
yield plugin;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
411
525
|
//#endregion
|
|
412
526
|
//#region src/lib/interactions/decorators/_shared.ts
|
|
413
527
|
function ensureChatInputCommandResolver(target) {
|
|
@@ -1390,48 +1504,6 @@ const Payloads = { Pong: JSON.stringify({ type: InteractionResponseType.Pong })
|
|
|
1390
1504
|
const Data = Symbol("data");
|
|
1391
1505
|
const Response = Symbol("response");
|
|
1392
1506
|
|
|
1393
|
-
//#endregion
|
|
1394
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
1395
|
-
function _typeof(o) {
|
|
1396
|
-
"@babel/helpers - typeof";
|
|
1397
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
1398
|
-
return typeof o;
|
|
1399
|
-
} : function(o) {
|
|
1400
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
1401
|
-
}, _typeof(o);
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
//#endregion
|
|
1405
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
1406
|
-
function toPrimitive(t, r) {
|
|
1407
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
1408
|
-
var e = t[Symbol.toPrimitive];
|
|
1409
|
-
if (void 0 !== e) {
|
|
1410
|
-
var i = e.call(t, r || "default");
|
|
1411
|
-
if ("object" != _typeof(i)) return i;
|
|
1412
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
1413
|
-
}
|
|
1414
|
-
return ("string" === r ? String : Number)(t);
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
|
-
//#endregion
|
|
1418
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
1419
|
-
function toPropertyKey(t) {
|
|
1420
|
-
var i = toPrimitive(t, "string");
|
|
1421
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
//#endregion
|
|
1425
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
1426
|
-
function _defineProperty(e, r, t) {
|
|
1427
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
1428
|
-
value: t,
|
|
1429
|
-
enumerable: !0,
|
|
1430
|
-
configurable: !0,
|
|
1431
|
-
writable: !0
|
|
1432
|
-
}) : e[r] = t, e;
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
1507
|
//#endregion
|
|
1436
1508
|
//#region src/lib/interactions/structures/interactions/base/BaseInteraction.ts
|
|
1437
1509
|
var BaseInteraction = class {
|
|
@@ -3246,14 +3318,28 @@ container$1.stores.register(new CommandStore());
|
|
|
3246
3318
|
container$1.stores.register(new InteractionHandlerStore());
|
|
3247
3319
|
container$1.stores.register(new ListenerStore());
|
|
3248
3320
|
var _discordPublicKey = /* @__PURE__ */ new WeakMap();
|
|
3249
|
-
var Client = class extends AsyncEventEmitter {
|
|
3321
|
+
var Client = class Client extends AsyncEventEmitter {
|
|
3250
3322
|
constructor(options = {}) {
|
|
3251
3323
|
super();
|
|
3252
3324
|
_defineProperty(this, "server", void 0);
|
|
3253
3325
|
_defineProperty(this, "id", void 0);
|
|
3326
|
+
_defineProperty(this, "options", void 0);
|
|
3254
3327
|
_defineProperty(this, "bodySizeLimit", void 0);
|
|
3255
3328
|
_defineProperty(this, "httpReplyOnError", void 0);
|
|
3256
3329
|
_classPrivateFieldInitSpec(this, _discordPublicKey, void 0);
|
|
3330
|
+
this.options = {
|
|
3331
|
+
...options,
|
|
3332
|
+
discordToken: void 0,
|
|
3333
|
+
discordPublicKey: void 0
|
|
3334
|
+
};
|
|
3335
|
+
for (const plugin of Client.plugins.values("preGenericsInitialization")) {
|
|
3336
|
+
plugin.hook.call(this, this.options);
|
|
3337
|
+
this.emit("pluginLoaded", plugin.type, plugin.name);
|
|
3338
|
+
}
|
|
3339
|
+
for (const plugin of Client.plugins.values("preInitialization")) {
|
|
3340
|
+
plugin.hook.call(this, this.options);
|
|
3341
|
+
this.emit("pluginLoaded", plugin.type, plugin.name);
|
|
3342
|
+
}
|
|
3257
3343
|
this.bodySizeLimit = options.bodySizeLimit ?? 1024 * 1024;
|
|
3258
3344
|
this.httpReplyOnError = options.httpReplyOnError ?? true;
|
|
3259
3345
|
const discordPublicKey = options.discordPublicKey ?? process.env.DISCORD_PUBLIC_KEY;
|
|
@@ -3271,6 +3357,20 @@ var Client = class extends AsyncEventEmitter {
|
|
|
3271
3357
|
rest: container$1.rest,
|
|
3272
3358
|
authPrefix: options.authPrefix
|
|
3273
3359
|
});
|
|
3360
|
+
for (const plugin of Client.plugins.values("postInitialization")) {
|
|
3361
|
+
plugin.hook.call(this, this.options);
|
|
3362
|
+
this.emit("pluginLoaded", plugin.type, plugin.name);
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
/**
|
|
3366
|
+
* Registers a plugin onto the {@link Client}, applying all of its hooks.
|
|
3367
|
+
*
|
|
3368
|
+
* @since 2.4.0
|
|
3369
|
+
* @param plugin The plugin to register.
|
|
3370
|
+
*/
|
|
3371
|
+
static use(plugin) {
|
|
3372
|
+
this.plugins.use(plugin);
|
|
3373
|
+
return this;
|
|
3274
3374
|
}
|
|
3275
3375
|
/**
|
|
3276
3376
|
* Gets the application command registry.
|
|
@@ -3286,6 +3386,10 @@ var Client = class extends AsyncEventEmitter {
|
|
|
3286
3386
|
* @param options The load options.
|
|
3287
3387
|
*/
|
|
3288
3388
|
async load(options = {}) {
|
|
3389
|
+
for (const plugin of Client.plugins.values("preLoad")) {
|
|
3390
|
+
await plugin.hook.call(this, this.options);
|
|
3391
|
+
this.emit("pluginLoaded", plugin.type, plugin.name);
|
|
3392
|
+
}
|
|
3289
3393
|
if (options.baseUserDirectory !== null) container$1.stores.registerPath(options.baseUserDirectory);
|
|
3290
3394
|
await container$1.stores.load();
|
|
3291
3395
|
}
|
|
@@ -3298,11 +3402,20 @@ var Client = class extends AsyncEventEmitter {
|
|
|
3298
3402
|
const path = postPath ?? process.env.HTTP_POST_PATH ?? "/";
|
|
3299
3403
|
this.server = createServer(serverOptions ?? {});
|
|
3300
3404
|
this.server.on("request", (request, response) => void this.handleRawHttpMessage(request, response, path, key));
|
|
3301
|
-
|
|
3405
|
+
await new Promise((resolve) => this.server.listen({
|
|
3302
3406
|
...listenOptions,
|
|
3303
3407
|
port,
|
|
3304
3408
|
host: address
|
|
3305
3409
|
}, resolve));
|
|
3410
|
+
try {
|
|
3411
|
+
for (const plugin of Client.plugins.values("postListen")) {
|
|
3412
|
+
await plugin.hook.call(this, this.options);
|
|
3413
|
+
this.emit("pluginLoaded", plugin.type, plugin.name);
|
|
3414
|
+
}
|
|
3415
|
+
} catch (error) {
|
|
3416
|
+
await new Promise((resolve) => this.server.close(() => resolve()));
|
|
3417
|
+
throw error;
|
|
3418
|
+
}
|
|
3306
3419
|
}
|
|
3307
3420
|
async handleRawHttpMessage(request, response, path, key) {
|
|
3308
3421
|
response.setHeader("Content-Type", "application/json");
|
|
@@ -3348,7 +3461,23 @@ var Client = class extends AsyncEventEmitter {
|
|
|
3348
3461
|
}
|
|
3349
3462
|
}
|
|
3350
3463
|
};
|
|
3464
|
+
_defineProperty(Client, "plugins", new PluginManager());
|
|
3465
|
+
|
|
3466
|
+
//#endregion
|
|
3467
|
+
//#region src/lib/plugins/Plugin.ts
|
|
3468
|
+
/**
|
|
3469
|
+
* The base class for all plugins. Plugins hook into the {@link Client}'s lifecycle by defining static
|
|
3470
|
+
* methods keyed by the plugin symbols. Use {@link PluginManager.use} (via `Client.use`) to register a plugin.
|
|
3471
|
+
*
|
|
3472
|
+
* @since 2.4.0
|
|
3473
|
+
*/
|
|
3474
|
+
var Plugin = class {};
|
|
3475
|
+
_defineProperty(Plugin, preGenericsInitialization, void 0);
|
|
3476
|
+
_defineProperty(Plugin, preInitialization, void 0);
|
|
3477
|
+
_defineProperty(Plugin, postInitialization, void 0);
|
|
3478
|
+
_defineProperty(Plugin, preLoad, void 0);
|
|
3479
|
+
_defineProperty(Plugin, postListen, void 0);
|
|
3351
3480
|
|
|
3352
3481
|
//#endregion
|
|
3353
|
-
export { AliasPiece, AliasStore, ApplicationCommandRegistry, ApplicationCommandRegistryEntry, AutocompleteInteraction, BaseInteraction, ChatInputCommandInteraction, Client, Command, CommandInteraction, CommandLoaderStrategy, CommandRouter, CommandStore, CommandStoreRouter, HttpCodes, InteractionHandler, InteractionHandlerStore, Listener, ListenerLoaderStrategy, ListenerStore, LoaderError, Message, MessageComponentButtonInteraction, MessageComponentChannelSelectInteraction, MessageComponentInteraction, MessageComponentMentionableSelectInteraction, MessageComponentRoleSelectInteraction, MessageComponentStringSelectInteraction as MessageComponentSelectMenuInteraction, MessageComponentStringSelectInteraction, MessageComponentUserSelectInteraction, MessageContextMenuCommandInteraction, MissingExportsError, ModalSubmitInteraction, PartialMessage, Piece, RegisterCommand, RegisterMessageCommand, RegisterSubcommand, RegisterSubcommandGroup, RegisterUserCommand, RestrictGuildIds, Store, StoreRegistry, StringIdParser, UserContextMenuCommandInteraction, applicationCommandRegistry, container, extractTopLevelOptions, makeInteraction, restrictedGuildIdRegistry, transformAutocompleteInteraction, transformInteraction, transformMessageInteraction, transformUserInteraction };
|
|
3482
|
+
export { AliasPiece, AliasStore, ApplicationCommandRegistry, ApplicationCommandRegistryEntry, AutocompleteInteraction, BaseInteraction, ChatInputCommandInteraction, Client, Command, CommandInteraction, CommandLoaderStrategy, CommandRouter, CommandStore, CommandStoreRouter, HttpCodes, InteractionHandler, InteractionHandlerStore, Listener, ListenerLoaderStrategy, ListenerStore, LoaderError, Message, MessageComponentButtonInteraction, MessageComponentChannelSelectInteraction, MessageComponentInteraction, MessageComponentMentionableSelectInteraction, MessageComponentRoleSelectInteraction, MessageComponentStringSelectInteraction as MessageComponentSelectMenuInteraction, MessageComponentStringSelectInteraction, MessageComponentUserSelectInteraction, MessageContextMenuCommandInteraction, MissingExportsError, ModalSubmitInteraction, PartialMessage, Piece, Plugin, PluginHook, PluginManager, RegisterCommand, RegisterMessageCommand, RegisterSubcommand, RegisterSubcommandGroup, RegisterUserCommand, RestrictGuildIds, Store, StoreRegistry, StringIdParser, UserContextMenuCommandInteraction, applicationCommandRegistry, container, extractTopLevelOptions, makeInteraction, postInitialization, postListen, preGenericsInitialization, preInitialization, preLoad, restrictedGuildIdRegistry, transformAutocompleteInteraction, transformInteraction, transformMessageInteraction, transformUserInteraction };
|
|
3354
3483
|
//# sourceMappingURL=index.js.map
|