seyfert 4.5.0 → 5.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/lib/api/Routes/cdn.d.ts +2 -2
- package/lib/api/Routes/guilds.d.ts +2 -2
- package/lib/api/Routes/invites.d.ts +2 -2
- package/lib/api/api.d.ts +20 -8
- package/lib/api/api.js +198 -44
- package/lib/api/shared.d.ts +30 -1
- package/lib/api/utils/constants.d.ts +1 -1
- package/lib/api/utils/constants.js +1 -1
- package/lib/api/utils/utils.d.ts +2 -1
- package/lib/api/utils/utils.js +1 -1
- package/lib/builders/Attachment.d.ts +1 -1
- package/lib/builders/Attachment.js +30 -8
- package/lib/builders/MediaGallery.d.ts +2 -2
- package/lib/builders/MediaGallery.js +10 -0
- package/lib/builders/Modal.d.ts +18 -8
- package/lib/builders/Modal.js +36 -7
- package/lib/builders/Poll.js +18 -0
- package/lib/builders/RadioGroup.d.ts +4 -3
- package/lib/builders/RadioGroup.js +24 -3
- package/lib/builders/SelectMenu.d.ts +8 -6
- package/lib/builders/SelectMenu.js +24 -3
- package/lib/builders/types.d.ts +3 -2
- package/lib/cache/adapters/default.d.ts +1 -1
- package/lib/cache/adapters/default.js +23 -26
- package/lib/cache/adapters/limited.d.ts +1 -0
- package/lib/cache/adapters/limited.js +47 -33
- package/lib/cache/index.d.ts +19 -25
- package/lib/cache/index.js +58 -6
- package/lib/cache/resources/bans.d.ts +1 -1
- package/lib/cache/resources/bans.js +4 -4
- package/lib/cache/resources/channels.d.ts +1 -1
- package/lib/cache/resources/channels.js +4 -4
- package/lib/cache/resources/default/base.d.ts +1 -1
- package/lib/cache/resources/default/base.js +8 -8
- package/lib/cache/resources/default/guild-based.d.ts +5 -5
- package/lib/cache/resources/default/guild-based.js +29 -16
- package/lib/cache/resources/default/guild-related.d.ts +5 -5
- package/lib/cache/resources/default/guild-related.js +14 -14
- package/lib/cache/resources/emojis.d.ts +1 -1
- package/lib/cache/resources/emojis.js +4 -4
- package/lib/cache/resources/guilds.js +28 -15
- package/lib/cache/resources/members.d.ts +1 -1
- package/lib/cache/resources/members.js +6 -6
- package/lib/cache/resources/messages.d.ts +7 -2
- package/lib/cache/resources/messages.js +43 -20
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/overwrites.js +5 -8
- package/lib/cache/resources/roles.d.ts +1 -1
- package/lib/cache/resources/roles.js +4 -4
- package/lib/cache/resources/stickers.d.ts +1 -1
- package/lib/cache/resources/stickers.js +4 -4
- package/lib/cache/resources/users.js +4 -4
- package/lib/cache/resources/voice-states.d.ts +1 -1
- package/lib/cache/resources/voice-states.js +4 -4
- package/lib/client/base.d.ts +83 -24
- package/lib/client/base.js +594 -39
- package/lib/client/client.d.ts +28 -3
- package/lib/client/client.js +33 -9
- package/lib/client/collectors.d.ts +9 -8
- package/lib/client/collectors.js +19 -52
- package/lib/client/httpclient.d.ts +3 -0
- package/lib/client/index.d.ts +3 -1
- package/lib/client/index.js +4 -0
- package/lib/client/intents.d.ts +3 -0
- package/lib/client/intents.js +9 -0
- package/lib/client/plugins/api.d.ts +4 -0
- package/lib/client/plugins/api.js +550 -0
- package/lib/client/plugins/errors.d.ts +25 -0
- package/lib/client/plugins/errors.js +79 -0
- package/lib/client/plugins/order.d.ts +10 -0
- package/lib/client/plugins/order.js +32 -0
- package/lib/client/plugins/registry.d.ts +273 -0
- package/lib/client/plugins/registry.js +868 -0
- package/lib/client/plugins/shared.d.ts +23 -0
- package/lib/client/plugins/shared.js +193 -0
- package/lib/client/plugins/types.d.ts +398 -0
- package/lib/client/plugins/types.js +8 -0
- package/lib/client/plugins.d.ts +78 -0
- package/lib/client/plugins.js +558 -0
- package/lib/client/transformers.d.ts +33 -33
- package/lib/client/workerclient.d.ts +10 -1
- package/lib/client/workerclient.js +27 -17
- package/lib/collection.d.ts +10 -8
- package/lib/collection.js +19 -25
- package/lib/commands/applications/chat.d.ts +20 -18
- package/lib/commands/applications/chat.js +39 -14
- package/lib/commands/applications/chatcontext.d.ts +23 -15
- package/lib/commands/applications/chatcontext.js +23 -2
- package/lib/commands/applications/entryPoint.d.ts +4 -3
- package/lib/commands/applications/entryPoint.js +1 -1
- package/lib/commands/applications/entrycontext.d.ts +7 -9
- package/lib/commands/applications/entrycontext.js +3 -1
- package/lib/commands/applications/menu.d.ts +4 -3
- package/lib/commands/applications/menucontext.d.ts +7 -9
- package/lib/commands/applications/menucontext.js +3 -1
- package/lib/commands/applications/options.d.ts +23 -23
- package/lib/commands/applications/shared.d.ts +39 -17
- package/lib/commands/decorators.d.ts +50 -38
- package/lib/commands/decorators.js +15 -5
- package/lib/commands/handle.d.ts +19 -8
- package/lib/commands/handle.js +224 -143
- package/lib/commands/handler.d.ts +21 -8
- package/lib/commands/handler.js +157 -69
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/optionresolver.d.ts +2 -2
- package/lib/common/it/colors.js +12 -2
- package/lib/common/it/error.d.ts +9 -0
- package/lib/common/it/error.js +8 -0
- package/lib/common/it/fake-promise.d.ts +4 -0
- package/lib/common/it/fake-promise.js +10 -0
- package/lib/common/it/formatter.d.ts +14 -11
- package/lib/common/it/formatter.js +4 -3
- package/lib/common/it/logger.d.ts +7 -1
- package/lib/common/it/logger.js +24 -6
- package/lib/common/it/utils.d.ts +6 -8
- package/lib/common/it/utils.js +44 -42
- package/lib/common/shorters/application.d.ts +3 -3
- package/lib/common/shorters/application.js +3 -2
- package/lib/common/shorters/bans.d.ts +8 -4
- package/lib/common/shorters/bans.js +13 -5
- package/lib/common/shorters/channels.d.ts +4 -4
- package/lib/common/shorters/channels.js +4 -4
- package/lib/common/shorters/emojis.js +1 -0
- package/lib/common/shorters/guilds.d.ts +8 -8
- package/lib/common/shorters/guilds.js +14 -31
- package/lib/common/shorters/interaction.d.ts +1 -1
- package/lib/common/shorters/invites.d.ts +201 -201
- package/lib/common/shorters/members.d.ts +7 -7
- package/lib/common/shorters/members.js +13 -14
- package/lib/common/shorters/messages.d.ts +2 -2
- package/lib/common/shorters/soundboard.d.ts +5 -5
- package/lib/common/shorters/users.d.ts +1 -1
- package/lib/common/shorters/webhook.d.ts +3 -2
- package/lib/common/shorters/webhook.js +0 -7
- package/lib/common/types/options.d.ts +4 -0
- package/lib/common/types/util.d.ts +8 -0
- package/lib/common/types/write.d.ts +2 -1
- package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
- package/lib/components/BaseSelectMenuComponent.js +1 -1
- package/lib/components/ButtonComponent.d.ts +3 -3
- package/lib/components/ChannelSelectMenuComponent.d.ts +2 -2
- package/lib/components/File.d.ts +1 -1
- package/lib/components/MediaGallery.d.ts +1 -1
- package/lib/components/MentionableSelectMenuComponent.d.ts +1 -1
- package/lib/components/RoleSelectMenuComponent.d.ts +1 -1
- package/lib/components/Separator.d.ts +1 -1
- package/lib/components/StringSelectMenuComponent.d.ts +1 -1
- package/lib/components/TextInputComponent.d.ts +1 -1
- package/lib/components/Thumbnail.d.ts +1 -1
- package/lib/components/UserSelectMenuComponent.d.ts +1 -1
- package/lib/components/componentcommand.d.ts +8 -7
- package/lib/components/componentcontext.d.ts +24 -36
- package/lib/components/componentcontext.js +7 -17
- package/lib/components/handler.d.ts +17 -7
- package/lib/components/handler.js +108 -49
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/interactioncontext.d.ts +45 -0
- package/lib/components/interactioncontext.js +93 -0
- package/lib/components/modalcommand.d.ts +5 -4
- package/lib/components/modalcontext.d.ts +39 -20
- package/lib/components/modalcontext.js +59 -6
- package/lib/events/event.d.ts +9 -3
- package/lib/events/handler.d.ts +51 -6
- package/lib/events/handler.js +165 -36
- package/lib/events/hooks/application_command.d.ts +1 -1
- package/lib/events/hooks/auto_moderation.d.ts +2 -2
- package/lib/events/hooks/guild.d.ts +150 -150
- package/lib/events/hooks/interactions.d.ts +1 -1
- package/lib/events/hooks/invite.d.ts +20 -20
- package/lib/events/hooks/message.d.ts +27 -27
- package/lib/events/hooks/presence.d.ts +11 -11
- package/lib/events/hooks/soundboard.d.ts +6 -6
- package/lib/events/hooks/stage.d.ts +2 -2
- package/lib/events/hooks/subscriptions.d.ts +3 -3
- package/lib/events/hooks/thread.d.ts +30 -30
- package/lib/events/hooks/voice.d.ts +3 -4
- package/lib/events/hooks/voice.js +2 -1
- package/lib/events/utils.d.ts +4 -0
- package/lib/events/utils.js +59 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +13 -8
- package/lib/langs/handler.d.ts +14 -11
- package/lib/langs/handler.js +46 -9
- package/lib/langs/router.d.ts +10 -3
- package/lib/structures/Application.d.ts +1 -1
- package/lib/structures/Emoji.d.ts +3 -3
- package/lib/structures/Emoji.js +2 -2
- package/lib/structures/Guild.d.ts +154 -154
- package/lib/structures/GuildBan.d.ts +4 -4
- package/lib/structures/GuildBan.js +3 -3
- package/lib/structures/GuildMember.d.ts +7 -7
- package/lib/structures/GuildMember.js +28 -7
- package/lib/structures/GuildRole.d.ts +1 -1
- package/lib/structures/GuildRole.js +2 -2
- package/lib/structures/Interaction.d.ts +11 -9
- package/lib/structures/Interaction.js +33 -12
- package/lib/structures/Message.d.ts +21 -14
- package/lib/structures/Message.js +29 -14
- package/lib/structures/User.d.ts +1 -1
- package/lib/structures/VoiceState.d.ts +4 -0
- package/lib/structures/VoiceState.js +13 -1
- package/lib/structures/Webhook.d.ts +9 -1
- package/lib/structures/Webhook.js +4 -1
- package/lib/structures/channels.d.ts +148 -134
- package/lib/structures/channels.js +27 -26
- package/lib/structures/extra/BitField.d.ts +4 -4
- package/lib/structures/extra/BitField.js +20 -4
- package/lib/structures/extra/DiscordBase.js +1 -1
- package/lib/structures/extra/Permissions.d.ts +2 -4
- package/lib/structures/extra/Permissions.js +1 -17
- package/lib/types/payloads/_interactions/responses.d.ts +2 -2
- package/lib/types/payloads/components.d.ts +4 -4
- package/lib/websocket/SharedTypes.d.ts +4 -4
- package/lib/websocket/constants/index.d.ts +1 -1
- package/lib/websocket/constants/index.js +3 -2
- package/lib/websocket/discord/events/memberUpdate.js +2 -2
- package/lib/websocket/discord/heartbeater.d.ts +1 -0
- package/lib/websocket/discord/heartbeater.js +7 -0
- package/lib/websocket/discord/shard.d.ts +2 -2
- package/lib/websocket/discord/shard.js +15 -13
- package/lib/websocket/discord/sharder.d.ts +8 -7
- package/lib/websocket/discord/sharder.js +25 -5
- package/lib/websocket/discord/shared.d.ts +19 -6
- package/lib/websocket/discord/socket/custom.js +5 -0
- package/lib/websocket/discord/worker.d.ts +1 -0
- package/lib/websocket/discord/worker.js +2 -0
- package/lib/websocket/discord/workermanager.d.ts +25 -11
- package/lib/websocket/discord/workermanager.js +41 -10
- package/package.json +12 -16
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Awaitable } from '../common/types/util';
|
|
2
|
+
import type { GatewayDispatchPayload } from '../types';
|
|
3
|
+
import type { BaseClient, BaseClientOptions, ContextScope, ContextScopeContext } from './base';
|
|
4
|
+
import { type GatewayIntentInput } from './intents';
|
|
5
|
+
import { type PluginRuntimeRegistry } from './plugins/registry';
|
|
6
|
+
export type { SeyfertPluginErrorCode } from './plugins/errors';
|
|
7
|
+
export { SeyfertPluginAggregateError, SeyfertPluginError } from './plugins/errors';
|
|
8
|
+
export { createSharedKey } from './plugins/shared';
|
|
9
|
+
export { PluginOrder } from './plugins/types';
|
|
10
|
+
import type { AnySeyfertPlugin, ExtendOf, PluginAutocompleteNext, PluginAutocompletePayload, PluginClientMap, PluginCommandObserver, PluginContextMap, PluginGatewaySendPayload, PluginHookName, PluginHookPayload, PluginMiddlewareMap, PluginRequirementInput, ResolvedPluginList, SeyfertPlugin, SeyfertPluginApi, SeyfertPluginClient, SeyfertPluginOptions, SeyfertPluginTeardownApi } from './plugins/types';
|
|
11
|
+
export type { AnySeyfertPlugin, ContextOf, ExtendOf, HandleableComponent, HandleableModal, MiddlewaresOf, PluginAutocompleteNext, PluginAutocompletePayload, PluginAutocompleteWrapper, PluginCacheResourceConstructor, PluginCacheResourceOptions, PluginClientMap, PluginCommandContributionOptions, PluginCommandLoadable, PluginCommandObserver, PluginCommandObserverCommand, PluginCommandObserverContext, PluginContextInteraction, PluginContextMap, PluginContextMapOf, PluginContextOf, PluginContributionOptions, PluginDiagnosticCode, PluginDiagnosticMessage, PluginDiagnosticSeverity, PluginDiagnostics, PluginDisposer, PluginEventErrorHandler, PluginExtensionOf, PluginGatewayDispatchInterceptor, PluginGatewayDispatchMeta, PluginGatewayDispatchNext, PluginGatewaySendPayload, PluginGatewaySendPayloadWrapper, PluginHandlerConstructor, PluginHandlerCreator, PluginHandlerInstance, PluginHandlerKind, PluginHandlerMetadata, PluginHandlerOptions, PluginHandlerTransformer, PluginHookHandler, PluginHookName, PluginHookPayload, PluginHookPayloadFor, PluginIntentResolvable, PluginLangOptions, PluginLifecyclePhase, PluginLifecycleStatus, PluginLoadedMetadata, PluginMiddlewareDenialMetadata, PluginMiddlewareMap, PluginMiddlewareOptions, PluginMiddlewaresMapOf, PluginMiddlewaresOf, PluginOrderOpt, PluginRequirement, PluginRequirementDiagnostic, PluginRequirementInput, PluginRestFailPayload, PluginRestObserver, PluginRestRatelimitPayload, PluginRestRequestPayload, PluginRestSuccessPayload, PluginSharedOptions, PluginSharedRegistry, PluginUploadCommandsMetadata, PluginUsingClient, RegisteredPluginContext, RegisteredPluginExtension, RegisteredPluginMiddlewares, RegisteredPluginShared, RegisteredPlugins, ResolvedPluginList, SemverRange, SeyfertCommandDefaults, SeyfertComponentDefaults, SeyfertModalDefaults, SeyfertPlugin, SeyfertPluginApi, SeyfertPluginClient, SeyfertPluginHooks, SeyfertPluginOptions, SeyfertPluginTeardownApi, SeyfertRegistry, SharedKey, SharedValue, } from './plugins/types';
|
|
12
|
+
type CreatePluginInputBase<Name extends string, I extends readonly AnySeyfertPlugin[], E extends object, C extends object, M extends PluginMiddlewareMap> = {
|
|
13
|
+
readonly name: Name;
|
|
14
|
+
readonly instanceId?: string;
|
|
15
|
+
readonly imports?: I;
|
|
16
|
+
readonly requires?: readonly PluginRequirementInput[];
|
|
17
|
+
readonly client?: PluginClientMap<E, I>;
|
|
18
|
+
readonly ctx?: PluginContextMap<C, I, E>;
|
|
19
|
+
readonly middlewares?: M;
|
|
20
|
+
readonly globalMiddlewares?: readonly (keyof M & string)[];
|
|
21
|
+
options?(current: Readonly<BaseClientOptions>): SeyfertPluginOptions;
|
|
22
|
+
register?(api: SeyfertPluginApi<M, ExtendOf<I> & E>): void;
|
|
23
|
+
setup?(client: SeyfertPluginClient & ExtendOf<I> & E, api?: SeyfertPluginApi<M, ExtendOf<I> & E>): Awaitable<void>;
|
|
24
|
+
teardown?(client: SeyfertPluginClient & ExtendOf<I> & E, api?: SeyfertPluginTeardownApi): Awaitable<void>;
|
|
25
|
+
};
|
|
26
|
+
type CreatePluginReservedKey = keyof CreatePluginInputBase<string, readonly AnySeyfertPlugin[], object, object, PluginMiddlewareMap> | 'meta';
|
|
27
|
+
type CreatePluginExtra<T extends object> = Omit<T, CreatePluginReservedKey>;
|
|
28
|
+
type CreatePluginInputWithMeta<Name extends string, I extends readonly AnySeyfertPlugin[], E extends object, C extends object, M extends PluginMiddlewareMap, Meta> = CreatePluginInputBase<Name, I, E, C, M> & {
|
|
29
|
+
readonly meta: Meta;
|
|
30
|
+
};
|
|
31
|
+
type CreatePluginInputWithoutMeta<Name extends string, I extends readonly AnySeyfertPlugin[], E extends object, C extends object, M extends PluginMiddlewareMap> = CreatePluginInputBase<Name, I, E, C, M> & {
|
|
32
|
+
readonly meta?: never;
|
|
33
|
+
};
|
|
34
|
+
type CreatePluginOutputBase<Name extends string, I extends readonly AnySeyfertPlugin[], E extends object, C extends object, M extends PluginMiddlewareMap> = Omit<SeyfertPlugin<E, C, I, M>, 'meta'> & {
|
|
35
|
+
readonly name: Name;
|
|
36
|
+
readonly instanceId?: string;
|
|
37
|
+
readonly imports?: I;
|
|
38
|
+
readonly requires?: readonly PluginRequirementInput[];
|
|
39
|
+
readonly client?: PluginClientMap<E, I>;
|
|
40
|
+
readonly ctx?: PluginContextMap<C, I, E>;
|
|
41
|
+
readonly middlewares?: M;
|
|
42
|
+
readonly globalMiddlewares?: readonly (keyof M & string)[];
|
|
43
|
+
};
|
|
44
|
+
type CreatePluginOutputWithMeta<Name extends string, I extends readonly AnySeyfertPlugin[], E extends object, C extends object, M extends PluginMiddlewareMap, Meta> = CreatePluginOutputBase<Name, I, E, C, M> & {
|
|
45
|
+
readonly meta: Meta;
|
|
46
|
+
};
|
|
47
|
+
export interface ResolvedClientPlugins {
|
|
48
|
+
plugins: ResolvedPluginList;
|
|
49
|
+
options: BaseClientOptions;
|
|
50
|
+
registry: PluginRuntimeRegistry;
|
|
51
|
+
}
|
|
52
|
+
export declare function createPlugin<const Name extends string, const I extends readonly AnySeyfertPlugin[] = readonly [], E extends object = {}, C extends object = {}, M extends PluginMiddlewareMap = {}, const Meta = never, const Extra extends object = {}>(plugin: CreatePluginInputWithMeta<Name, I, E, C, M, Meta> & Extra): CreatePluginOutputWithMeta<Name, I, E, C, M, Meta> & CreatePluginExtra<Extra>;
|
|
53
|
+
export declare function createPlugin<const Name extends string, const I extends readonly AnySeyfertPlugin[] = readonly [], E extends object = {}, C extends object = {}, M extends PluginMiddlewareMap = {}, const Extra extends object = {}>(plugin: CreatePluginInputWithoutMeta<Name, I, E, C, M> & Extra): CreatePluginOutputBase<Name, I, E, C, M> & CreatePluginExtra<Extra>;
|
|
54
|
+
export declare function createPluginFactory<O extends object, P extends AnySeyfertPlugin>(setup: {
|
|
55
|
+
defaults: O;
|
|
56
|
+
validate?: (options: O) => void;
|
|
57
|
+
factory: (options: O) => P;
|
|
58
|
+
}): (options?: Partial<O>) => P;
|
|
59
|
+
export declare function definePlugins<const TPlugins extends readonly AnySeyfertPlugin[]>(plugins: TPlugins): TPlugins;
|
|
60
|
+
export declare function definePlugins<const TPlugins extends readonly AnySeyfertPlugin[]>(...plugins: TPlugins): TPlugins;
|
|
61
|
+
export declare function createContextScope(scope: ContextScope): ContextScope;
|
|
62
|
+
export declare function resolveClientPlugins(defaults: BaseClientOptions, options?: BaseClientOptions): ResolvedClientPlugins;
|
|
63
|
+
export declare function bindClientPlugins(client: BaseClient, registry: PluginRuntimeRegistry): void;
|
|
64
|
+
export declare function refreshClientPluginGlobalMiddlewares(client: BaseClient, registry: PluginRuntimeRegistry): void;
|
|
65
|
+
export declare function refreshClientPluginOptions(client: BaseClient, registry: PluginRuntimeRegistry): void;
|
|
66
|
+
export declare function resolveClientPluginIntents(client: BaseClient, base?: GatewayIntentInput): number;
|
|
67
|
+
export declare function runPluginAutocompleteWrappers(client: BaseClient, payload: PluginAutocompletePayload, run: PluginAutocompleteNext): Awaitable<void>;
|
|
68
|
+
export declare function runPluginCommandObservers<K extends keyof PluginCommandObserver>(client: BaseClient, name: K, ...args: Parameters<NonNullable<PluginCommandObserver[K]>>): Promise<void>;
|
|
69
|
+
export declare function runPluginHooks<K extends PluginHookName>(client: BaseClient, name: K, ...args: PluginHookPayload<K>): Promise<void>;
|
|
70
|
+
export declare function applyPluginGatewayDispatchInterceptors(client: BaseClient, shardId: number, packet: GatewayDispatchPayload): Promise<GatewayDispatchPayload | null>;
|
|
71
|
+
export declare function applyPluginGatewaySendPayloadWrappers(client: BaseClient, shardId: number, payload: PluginGatewaySendPayload['payload']): Promise<import("..").GatewaySendPayload | null>;
|
|
72
|
+
export declare function setupClientPlugins(client: BaseClient & {
|
|
73
|
+
plugins: ResolvedPluginList;
|
|
74
|
+
}, plugins: ResolvedPluginList): Promise<void>;
|
|
75
|
+
export declare function teardownClientPlugins(client: BaseClient & {
|
|
76
|
+
plugins: ResolvedPluginList;
|
|
77
|
+
}, plugins: readonly AnySeyfertPlugin[]): Promise<void>;
|
|
78
|
+
export declare function runContextScopes<T>(scopes: readonly ContextScope[] | undefined, context: ContextScopeContext, run: () => Awaitable<T>): Awaitable<T>;
|
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginOrder = exports.createSharedKey = exports.SeyfertPluginError = exports.SeyfertPluginAggregateError = void 0;
|
|
4
|
+
exports.createPlugin = createPlugin;
|
|
5
|
+
exports.createPluginFactory = createPluginFactory;
|
|
6
|
+
exports.definePlugins = definePlugins;
|
|
7
|
+
exports.createContextScope = createContextScope;
|
|
8
|
+
exports.resolveClientPlugins = resolveClientPlugins;
|
|
9
|
+
exports.bindClientPlugins = bindClientPlugins;
|
|
10
|
+
exports.refreshClientPluginGlobalMiddlewares = refreshClientPluginGlobalMiddlewares;
|
|
11
|
+
exports.refreshClientPluginOptions = refreshClientPluginOptions;
|
|
12
|
+
exports.resolveClientPluginIntents = resolveClientPluginIntents;
|
|
13
|
+
exports.runPluginAutocompleteWrappers = runPluginAutocompleteWrappers;
|
|
14
|
+
exports.runPluginCommandObservers = runPluginCommandObservers;
|
|
15
|
+
exports.runPluginHooks = runPluginHooks;
|
|
16
|
+
exports.applyPluginGatewayDispatchInterceptors = applyPluginGatewayDispatchInterceptors;
|
|
17
|
+
exports.applyPluginGatewaySendPayloadWrappers = applyPluginGatewaySendPayloadWrappers;
|
|
18
|
+
exports.setupClientPlugins = setupClientPlugins;
|
|
19
|
+
exports.teardownClientPlugins = teardownClientPlugins;
|
|
20
|
+
exports.runContextScopes = runContextScopes;
|
|
21
|
+
const common_1 = require("../common");
|
|
22
|
+
const intents_1 = require("./intents");
|
|
23
|
+
const api_1 = require("./plugins/api");
|
|
24
|
+
const errors_1 = require("./plugins/errors");
|
|
25
|
+
const order_1 = require("./plugins/order");
|
|
26
|
+
const registry_1 = require("./plugins/registry");
|
|
27
|
+
const shared_1 = require("./plugins/shared");
|
|
28
|
+
var errors_2 = require("./plugins/errors");
|
|
29
|
+
Object.defineProperty(exports, "SeyfertPluginAggregateError", { enumerable: true, get: function () { return errors_2.SeyfertPluginAggregateError; } });
|
|
30
|
+
Object.defineProperty(exports, "SeyfertPluginError", { enumerable: true, get: function () { return errors_2.SeyfertPluginError; } });
|
|
31
|
+
var shared_2 = require("./plugins/shared");
|
|
32
|
+
Object.defineProperty(exports, "createSharedKey", { enumerable: true, get: function () { return shared_2.createSharedKey; } });
|
|
33
|
+
var types_1 = require("./plugins/types");
|
|
34
|
+
Object.defineProperty(exports, "PluginOrder", { enumerable: true, get: function () { return types_1.PluginOrder; } });
|
|
35
|
+
function createPlugin(plugin) {
|
|
36
|
+
return plugin;
|
|
37
|
+
}
|
|
38
|
+
function createPluginFactory(setup) {
|
|
39
|
+
return (options) => {
|
|
40
|
+
const resolved = { ...setup.defaults, ...options };
|
|
41
|
+
try {
|
|
42
|
+
setup.validate?.(resolved);
|
|
43
|
+
return setup.factory(resolved);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw (0, errors_1.wrapPluginError)('<createPluginFactory>', 'options', -1, error);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function definePlugins(...plugins) {
|
|
51
|
+
return (Array.isArray(plugins[0]) ? plugins[0] : plugins);
|
|
52
|
+
}
|
|
53
|
+
function createContextScope(scope) {
|
|
54
|
+
return scope;
|
|
55
|
+
}
|
|
56
|
+
const commandHookKeys = [
|
|
57
|
+
'onBeforeMiddlewares',
|
|
58
|
+
'onBeforeOptions',
|
|
59
|
+
'onRunError',
|
|
60
|
+
'onPermissionsFail',
|
|
61
|
+
'onBotPermissionsFail',
|
|
62
|
+
'onInternalError',
|
|
63
|
+
'onMiddlewaresError',
|
|
64
|
+
'onOptionsError',
|
|
65
|
+
'onAfterRun',
|
|
66
|
+
];
|
|
67
|
+
const componentHookKeys = [
|
|
68
|
+
'onBeforeMiddlewares',
|
|
69
|
+
'onRunError',
|
|
70
|
+
'onInternalError',
|
|
71
|
+
'onMiddlewaresError',
|
|
72
|
+
'onAfterRun',
|
|
73
|
+
];
|
|
74
|
+
const modalHookKeys = [
|
|
75
|
+
'onBeforeMiddlewares',
|
|
76
|
+
'onRunError',
|
|
77
|
+
'onInternalError',
|
|
78
|
+
'onMiddlewaresError',
|
|
79
|
+
'onAfterRun',
|
|
80
|
+
];
|
|
81
|
+
function resolveClientPlugins(defaults, options = {}) {
|
|
82
|
+
const registry = (0, registry_1.createPluginRuntimeRegistry)(options.plugins);
|
|
83
|
+
const userOptions = omitPlugins(options);
|
|
84
|
+
const pluginOptionContributions = [];
|
|
85
|
+
const addPluginOption = (record, fragment) => {
|
|
86
|
+
pluginOptionContributions.push({
|
|
87
|
+
record,
|
|
88
|
+
fragment: (0, registry_1.clonePluginOptions)(fragment),
|
|
89
|
+
sequence: (0, order_1.nextPluginContributionSequence)(registry),
|
|
90
|
+
scope: 'register',
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
const pluginOptions = () => pluginOptionContributions.map(contribution => contribution.fragment);
|
|
94
|
+
for (const record of registry.records) {
|
|
95
|
+
const contextFragment = (0, registry_1.createPluginContextFragment)(record, registry);
|
|
96
|
+
if (contextFragment)
|
|
97
|
+
addPluginOption(record, contextFragment);
|
|
98
|
+
if (record.plugin.globalMiddlewares?.length) {
|
|
99
|
+
const globalMiddlewares = record.plugin.globalMiddlewares;
|
|
100
|
+
(0, registry_1.addPluginGlobalMiddlewares)(registry, record, globalMiddlewares);
|
|
101
|
+
addPluginOption(record, { globalMiddlewares: globalMiddlewares });
|
|
102
|
+
}
|
|
103
|
+
const current = (0, registry_1.readonlyPluginOptions)((0, common_1.MergeOptions)(defaults, ...pluginOptions(), userOptions));
|
|
104
|
+
try {
|
|
105
|
+
const fragment = record.plugin.options?.(current);
|
|
106
|
+
if (fragment)
|
|
107
|
+
addPluginOption(record, fragment);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw (0, errors_1.wrapPluginError)(record.plugin.name, 'options', record.index, error, undefined, record.plugin.instanceId);
|
|
111
|
+
}
|
|
112
|
+
(0, registry_1.runPluginRegister)(record, registry);
|
|
113
|
+
pluginOptionContributions.push(...record.optionFragments);
|
|
114
|
+
}
|
|
115
|
+
(0, registry_1.validatePluginRequirements)(registry, 'capability');
|
|
116
|
+
const optionFragments = pluginOptions();
|
|
117
|
+
const merged = (0, common_1.MergeOptions)(defaults, ...optionFragments, userOptions);
|
|
118
|
+
merged.plugins = registry.plugins;
|
|
119
|
+
registry.globalMiddlewareOptions = {
|
|
120
|
+
defaults,
|
|
121
|
+
pluginOptions: pluginOptionContributions,
|
|
122
|
+
userOptions,
|
|
123
|
+
};
|
|
124
|
+
composeContext(merged, defaults, optionFragments, userOptions);
|
|
125
|
+
composeContextScopes(merged, defaults, optionFragments, userOptions);
|
|
126
|
+
composeGlobalMiddlewares(merged, defaults, pluginOptionContributions, userOptions, registry);
|
|
127
|
+
const commandDefaultContributions = collectPluginDefaultContributions(pluginOptionContributions, registry.pluginDefaults, 'commands');
|
|
128
|
+
composeDefaults(merged.commands?.defaults, defaults.commands?.defaults, commandDefaultContributions, userOptions.commands?.defaults, commandHookKeys);
|
|
129
|
+
composeCommandProps(merged.commands?.defaults, defaults.commands?.defaults, commandDefaultContributions, userOptions.commands?.defaults);
|
|
130
|
+
composeDefaults(merged.components?.defaults, defaults.components?.defaults, collectPluginDefaultContributions(pluginOptionContributions, registry.pluginDefaults, 'components'), userOptions.components?.defaults, componentHookKeys);
|
|
131
|
+
composeDefaults(merged.modals?.defaults, defaults.modals?.defaults, collectPluginDefaultContributions(pluginOptionContributions, registry.pluginDefaults, 'modals'), userOptions.modals?.defaults, modalHookKeys);
|
|
132
|
+
return { plugins: registry.plugins, options: merged, registry };
|
|
133
|
+
}
|
|
134
|
+
function bindClientPlugins(client, registry) {
|
|
135
|
+
(0, registry_1.bindPluginClient)(registry, client);
|
|
136
|
+
(0, registry_1.installPluginClientMaps)(client, registry);
|
|
137
|
+
(0, registry_1.installPluginMiddlewares)(client, registry);
|
|
138
|
+
}
|
|
139
|
+
function refreshClientPluginGlobalMiddlewares(client, registry) {
|
|
140
|
+
const sources = registry.globalMiddlewareOptions;
|
|
141
|
+
if (!sources)
|
|
142
|
+
return;
|
|
143
|
+
composeGlobalMiddlewares(client.options, sources.defaults, sources.pluginOptions, sources.userOptions, registry);
|
|
144
|
+
}
|
|
145
|
+
function refreshClientPluginOptions(client, registry) {
|
|
146
|
+
const sources = registry.globalMiddlewareOptions;
|
|
147
|
+
if (!sources)
|
|
148
|
+
return;
|
|
149
|
+
const optionFragments = sources.pluginOptions.map(contribution => contribution.fragment);
|
|
150
|
+
const merged = (0, common_1.MergeOptions)(sources.defaults, ...optionFragments, sources.userOptions);
|
|
151
|
+
merged.plugins = registry.plugins;
|
|
152
|
+
composeContext(merged, sources.defaults, optionFragments, sources.userOptions);
|
|
153
|
+
composeContextScopes(merged, sources.defaults, optionFragments, sources.userOptions);
|
|
154
|
+
composeGlobalMiddlewares(merged, sources.defaults, sources.pluginOptions, sources.userOptions, registry);
|
|
155
|
+
const commandDefaultContributions = collectPluginDefaultContributions(sources.pluginOptions, registry.pluginDefaults, 'commands');
|
|
156
|
+
composeDefaults(merged.commands?.defaults, sources.defaults.commands?.defaults, commandDefaultContributions, sources.userOptions.commands?.defaults, commandHookKeys);
|
|
157
|
+
composeCommandProps(merged.commands?.defaults, sources.defaults.commands?.defaults, commandDefaultContributions, sources.userOptions.commands?.defaults);
|
|
158
|
+
composeDefaults(merged.components?.defaults, sources.defaults.components?.defaults, collectPluginDefaultContributions(sources.pluginOptions, registry.pluginDefaults, 'components'), sources.userOptions.components?.defaults, componentHookKeys);
|
|
159
|
+
composeDefaults(merged.modals?.defaults, sources.defaults.modals?.defaults, collectPluginDefaultContributions(sources.pluginOptions, registry.pluginDefaults, 'modals'), sources.userOptions.modals?.defaults, modalHookKeys);
|
|
160
|
+
client.options = merged;
|
|
161
|
+
}
|
|
162
|
+
function resolveClientPluginIntents(client, base) {
|
|
163
|
+
return (0, registry_1.resolvePluginIntents)(client.pluginRegistry, (0, intents_1.resolveGatewayIntents)(base));
|
|
164
|
+
}
|
|
165
|
+
function runPluginAutocompleteWrappers(client, payload, run) {
|
|
166
|
+
const wrappers = client.pluginRegistry.autocompleteWrappers;
|
|
167
|
+
if (!wrappers.length)
|
|
168
|
+
return run();
|
|
169
|
+
const dispatch = (0, order_1.orderedPluginContributions)(wrappers).reduceRight((next, contribution) => () => Promise.resolve(contribution.wrapper(payload, next)).catch(error => {
|
|
170
|
+
throw (0, errors_1.wrapPluginError)(contribution.record.plugin.name, 'autocomplete.wrap', contribution.record.index, error, undefined, contribution.record.plugin.instanceId);
|
|
171
|
+
}), run);
|
|
172
|
+
return dispatch();
|
|
173
|
+
}
|
|
174
|
+
async function runPluginCommandObservers(client, name, ...args) {
|
|
175
|
+
const observers = (0, order_1.orderedPluginContributions)(client.pluginRegistry.commandObservers).filter(contribution => contribution.active);
|
|
176
|
+
for (const contribution of observers) {
|
|
177
|
+
const observer = contribution.observer[name];
|
|
178
|
+
if (!observer)
|
|
179
|
+
continue;
|
|
180
|
+
try {
|
|
181
|
+
await observer(...args);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
client.logger.error(`[plugin:${contribution.record.plugin.name}] command observer "${String(name)}" failed`, error);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function runPluginHooks(client, name, ...args) {
|
|
189
|
+
const hooks = (0, order_1.orderedPluginContributions)(client.pluginRegistry.hooks).filter(contribution => contribution.active && contribution.name === name);
|
|
190
|
+
for (const contribution of hooks) {
|
|
191
|
+
try {
|
|
192
|
+
await contribution.handler(...args);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
await reportPluginHookFailure(client, name, (0, errors_1.wrapPluginError)(contribution.record.plugin.name, `hook:${name}`, contribution.record.index, error, undefined, contribution.record.plugin.instanceId));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async function reportPluginHookFailure(client, name, error) {
|
|
200
|
+
const observers = (0, order_1.orderedPluginContributions)(client.pluginRegistry.eventErrors).filter(contribution => contribution.active);
|
|
201
|
+
for (const contribution of observers) {
|
|
202
|
+
try {
|
|
203
|
+
await contribution.handler(error, `hook:${name}`);
|
|
204
|
+
}
|
|
205
|
+
catch (observerError) {
|
|
206
|
+
client.logger.warn('<Client>.hooks.onError', observerError, name);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
client.logger.warn('<Client>.hooks.onFail', error, name);
|
|
210
|
+
}
|
|
211
|
+
async function applyPluginGatewayDispatchInterceptors(client, shardId, packet) {
|
|
212
|
+
const interceptors = (0, order_1.orderedPluginContributions)(client.pluginRegistry.gatewayDispatchInterceptors);
|
|
213
|
+
if (!interceptors.length)
|
|
214
|
+
return packet;
|
|
215
|
+
const run = async (index, current) => {
|
|
216
|
+
const contribution = interceptors[index];
|
|
217
|
+
if (!contribution)
|
|
218
|
+
return current;
|
|
219
|
+
let nextCalled = false;
|
|
220
|
+
let nextResult;
|
|
221
|
+
let nextValue;
|
|
222
|
+
const next = nextPacket => {
|
|
223
|
+
if (nextCalled) {
|
|
224
|
+
throw new Error('gateway.onDispatch next() was called multiple times.');
|
|
225
|
+
}
|
|
226
|
+
nextCalled = true;
|
|
227
|
+
nextResult = run(index + 1, nextPacket ?? current).then(value => {
|
|
228
|
+
nextValue = value;
|
|
229
|
+
return value;
|
|
230
|
+
});
|
|
231
|
+
return nextResult;
|
|
232
|
+
};
|
|
233
|
+
let result;
|
|
234
|
+
try {
|
|
235
|
+
result = await contribution.interceptor(current, next, { client, shardId });
|
|
236
|
+
if (nextCalled)
|
|
237
|
+
nextValue = await nextResult;
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
throw (0, errors_1.wrapPluginError)(contribution.record.plugin.name, 'gateway.onDispatch', contribution.record.index, error, undefined, contribution.record.plugin.instanceId);
|
|
241
|
+
}
|
|
242
|
+
if (nextCalled && nextValue === null)
|
|
243
|
+
return null;
|
|
244
|
+
if (result === null) {
|
|
245
|
+
(0, registry_1.addPluginDiagnostic)(client.pluginRegistry, contribution.record, {
|
|
246
|
+
phase: 'gateway.onDispatch',
|
|
247
|
+
severity: 'warn',
|
|
248
|
+
code: 'gateway-dispatch-veto',
|
|
249
|
+
message: `Gateway dispatch interceptor from plugin "${contribution.record.plugin.name}" vetoed a dispatch packet.`,
|
|
250
|
+
data: { shardId, op: current.op, event: current.t },
|
|
251
|
+
});
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
if (nextCalled)
|
|
255
|
+
return result ?? nextValue ?? current;
|
|
256
|
+
return run(index + 1, result ?? current);
|
|
257
|
+
};
|
|
258
|
+
return run(0, packet);
|
|
259
|
+
}
|
|
260
|
+
async function applyPluginGatewaySendPayloadWrappers(client, shardId, payload) {
|
|
261
|
+
let current = payload;
|
|
262
|
+
for (const contribution of (0, order_1.orderedPluginContributions)(client.pluginRegistry.gatewaySendPayloadWrappers)) {
|
|
263
|
+
let result;
|
|
264
|
+
try {
|
|
265
|
+
result = await contribution.wrapper({ client, shardId, payload: current });
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
throw (0, errors_1.wrapPluginError)(contribution.record.plugin.name, 'gateway.wrapSendPayload', contribution.record.index, error, undefined, contribution.record.plugin.instanceId);
|
|
269
|
+
}
|
|
270
|
+
if (result === null) {
|
|
271
|
+
(0, registry_1.addPluginDiagnostic)(client.pluginRegistry, contribution.record, {
|
|
272
|
+
phase: 'gateway.wrapSendPayload',
|
|
273
|
+
severity: 'warn',
|
|
274
|
+
code: 'gateway-send-payload-veto',
|
|
275
|
+
message: `Gateway send payload wrapper from plugin "${contribution.record.plugin.name}" vetoed a payload.`,
|
|
276
|
+
data: { shardId, op: current.op },
|
|
277
|
+
});
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
if (result !== undefined)
|
|
281
|
+
current = result;
|
|
282
|
+
}
|
|
283
|
+
return current;
|
|
284
|
+
}
|
|
285
|
+
async function setupClientPlugins(client, plugins) {
|
|
286
|
+
const completed = [];
|
|
287
|
+
const records = getPluginRecords(client, plugins);
|
|
288
|
+
try {
|
|
289
|
+
for (const record of records) {
|
|
290
|
+
const plugin = record.plugin;
|
|
291
|
+
try {
|
|
292
|
+
record.status = 'setting-up';
|
|
293
|
+
const registry = client.pluginRegistry;
|
|
294
|
+
if (registry)
|
|
295
|
+
(0, registry_1.activatePluginEventListeners)(registry, record);
|
|
296
|
+
await plugin.setup?.(client, registry ? (0, api_1.createPluginApi)(record, registry, 'setup') : undefined);
|
|
297
|
+
record.status = 'ready';
|
|
298
|
+
completed.push(record);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
record.status = 'failed';
|
|
302
|
+
const setupError = (0, errors_1.wrapPluginError)(plugin.name, 'setup', record.index, error, undefined, plugin.instanceId);
|
|
303
|
+
const registry = client.pluginRegistry;
|
|
304
|
+
if (registry)
|
|
305
|
+
(0, registry_1.cleanupPluginEventListeners)(registry, record);
|
|
306
|
+
const cleanupErrors = registry ? await (0, shared_1.disposePluginSharedValues)(client.shared, registry, record) : [];
|
|
307
|
+
const sharedMutationErrors = registry ? await (0, shared_1.cleanupPluginDynamicSharedContributions)(registry, record) : [];
|
|
308
|
+
if (registry)
|
|
309
|
+
(0, registry_1.cleanupPluginDynamicContributionMutations)(registry, record);
|
|
310
|
+
refreshClientPluginContributions(client);
|
|
311
|
+
if (cleanupErrors.length || sharedMutationErrors.length) {
|
|
312
|
+
throw new errors_1.SeyfertPluginAggregateError('PLUGIN_FAILED', '<multiple>', 'setup', -1, [setupError, ...cleanupErrors, ...sharedMutationErrors], 'Seyfert plugin setup failed and cleanup also failed.', setupError);
|
|
313
|
+
}
|
|
314
|
+
throw setupError;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
catch (setupError) {
|
|
319
|
+
try {
|
|
320
|
+
await teardownPluginRecords(client, completed);
|
|
321
|
+
}
|
|
322
|
+
catch (teardownError) {
|
|
323
|
+
throw new errors_1.SeyfertPluginAggregateError('PLUGIN_FAILED', '<multiple>', 'setup', -1, [setupError, teardownError], 'Seyfert plugin setup failed and cleanup also failed.', setupError);
|
|
324
|
+
}
|
|
325
|
+
throw setupError;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async function teardownClientPlugins(client, plugins) {
|
|
329
|
+
await teardownPluginRecords(client, getPluginRecords(client, plugins));
|
|
330
|
+
}
|
|
331
|
+
async function teardownPluginRecords(client, records) {
|
|
332
|
+
const errors = [];
|
|
333
|
+
try {
|
|
334
|
+
for (const record of [...records].reverse()) {
|
|
335
|
+
const plugin = record.plugin;
|
|
336
|
+
let failed = false;
|
|
337
|
+
record.status = 'closing';
|
|
338
|
+
if (client.pluginRegistry)
|
|
339
|
+
(0, registry_1.cleanupPluginEventListeners)(client.pluginRegistry, record);
|
|
340
|
+
const registry = client.pluginRegistry;
|
|
341
|
+
try {
|
|
342
|
+
await plugin.teardown?.(client, registry ? (0, api_1.createPluginApi)(record, registry, 'teardown') : undefined);
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
failed = true;
|
|
346
|
+
errors.push((0, errors_1.wrapPluginError)(plugin.name, 'teardown', record.index, error, 'PLUGIN_TEARDOWN_FAILED', plugin.instanceId));
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
if (registry)
|
|
350
|
+
(0, registry_1.cleanupPluginEventListeners)(registry, record);
|
|
351
|
+
}
|
|
352
|
+
if (registry) {
|
|
353
|
+
const sharedErrors = await (0, shared_1.disposePluginSharedValues)(client.shared, registry, record);
|
|
354
|
+
if (sharedErrors.length) {
|
|
355
|
+
failed = true;
|
|
356
|
+
errors.push(...sharedErrors);
|
|
357
|
+
}
|
|
358
|
+
const sharedMutationErrors = await (0, shared_1.cleanupPluginDynamicSharedContributions)(registry, record);
|
|
359
|
+
if (sharedMutationErrors.length) {
|
|
360
|
+
failed = true;
|
|
361
|
+
errors.push(...sharedMutationErrors);
|
|
362
|
+
}
|
|
363
|
+
(0, registry_1.cleanupPluginDynamicContributionMutations)(registry, record);
|
|
364
|
+
}
|
|
365
|
+
record.status = failed ? 'failed' : 'closed';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
finally {
|
|
369
|
+
if (client.shared)
|
|
370
|
+
(0, shared_1.clearSharedRegistryInstances)(client.shared);
|
|
371
|
+
refreshClientPluginContributions(client);
|
|
372
|
+
}
|
|
373
|
+
if (errors.length) {
|
|
374
|
+
throw new errors_1.SeyfertPluginAggregateError('PLUGIN_TEARDOWN_FAILED', '<multiple>', 'teardown', -1, errors, 'Seyfert plugin teardown failed.');
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function getPluginRecords(client, plugins) {
|
|
378
|
+
const records = client.pluginRegistry?.records ?? [];
|
|
379
|
+
return plugins.map((plugin, index) => {
|
|
380
|
+
const record = records.find(record => record.plugin === plugin);
|
|
381
|
+
if (record)
|
|
382
|
+
return record;
|
|
383
|
+
return {
|
|
384
|
+
plugin,
|
|
385
|
+
identity: (0, registry_1.pluginIdentity)(plugin),
|
|
386
|
+
index,
|
|
387
|
+
imports: plugin.imports ?? [],
|
|
388
|
+
clientKeys: Object.keys(plugin.client ?? {}),
|
|
389
|
+
ctxKeys: Object.keys(plugin.ctx ?? {}),
|
|
390
|
+
optionFragments: [],
|
|
391
|
+
status: 'registered',
|
|
392
|
+
};
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function refreshClientPluginContributions(client) {
|
|
396
|
+
client.refreshPluginContributions?.();
|
|
397
|
+
}
|
|
398
|
+
function runContextScopes(scopes, context, run) {
|
|
399
|
+
if (!scopes?.length)
|
|
400
|
+
return run();
|
|
401
|
+
const scopedRun = scopes.reduceRight((next, scope) => () => scope(context, next), run);
|
|
402
|
+
return scopedRun();
|
|
403
|
+
}
|
|
404
|
+
function omitPlugins(options) {
|
|
405
|
+
const { plugins: _plugins, ...rest } = options;
|
|
406
|
+
return rest;
|
|
407
|
+
}
|
|
408
|
+
function composeContext(target, defaults, pluginOptions, userOptions) {
|
|
409
|
+
const callbacks = [];
|
|
410
|
+
if (typeof defaults.context === 'function')
|
|
411
|
+
callbacks.push(defaults.context);
|
|
412
|
+
callbacks.push(...pluginOptions
|
|
413
|
+
.map(fragment => fragment.context)
|
|
414
|
+
.filter((callback) => typeof callback === 'function'));
|
|
415
|
+
if (typeof userOptions.context === 'function')
|
|
416
|
+
callbacks.push(userOptions.context);
|
|
417
|
+
if (!callbacks.length)
|
|
418
|
+
return;
|
|
419
|
+
target.context = interaction => callbacks.reduce((context, callback) => Object.assign(context, callback(interaction)), {});
|
|
420
|
+
}
|
|
421
|
+
function composeContextScopes(target, defaults, pluginOptions, userOptions) {
|
|
422
|
+
const scopes = [
|
|
423
|
+
...(defaults.contextScopes ?? []),
|
|
424
|
+
...pluginOptions.flatMap(fragment => fragment.contextScopes ?? []),
|
|
425
|
+
...(userOptions.contextScopes ?? []),
|
|
426
|
+
];
|
|
427
|
+
if (scopes.length)
|
|
428
|
+
target.contextScopes = scopes;
|
|
429
|
+
}
|
|
430
|
+
function composeGlobalMiddlewares(target, defaults, pluginOptions, userOptions, registry) {
|
|
431
|
+
const registryMiddlewares = collectActiveRegistryGlobalMiddlewares(registry);
|
|
432
|
+
const registryMiddlewareNames = new Set([...registry.globalMiddlewares, ...registry.middlewares.filter(contribution => contribution.global)].map(contribution => contribution.name));
|
|
433
|
+
const optionMiddlewares = pluginOptions.flatMap(contribution => (contribution.fragment.globalMiddlewares ?? [])
|
|
434
|
+
.map(name => String(name))
|
|
435
|
+
.filter(name => !registryMiddlewareNames.has(name))
|
|
436
|
+
.map(name => ({
|
|
437
|
+
name,
|
|
438
|
+
sequence: contribution.sequence,
|
|
439
|
+
})));
|
|
440
|
+
const pluginMiddlewares = (0, order_1.orderedPluginContributions)([
|
|
441
|
+
...registryMiddlewares,
|
|
442
|
+
...optionMiddlewares,
|
|
443
|
+
]).map(contribution => contribution.name);
|
|
444
|
+
const middlewares = uniqueMiddlewareNames([
|
|
445
|
+
...(defaults.globalMiddlewares ?? []),
|
|
446
|
+
...pluginMiddlewares,
|
|
447
|
+
...(userOptions.globalMiddlewares ?? []),
|
|
448
|
+
]);
|
|
449
|
+
if (middlewares.length)
|
|
450
|
+
target.globalMiddlewares = middlewares;
|
|
451
|
+
else
|
|
452
|
+
delete target.globalMiddlewares;
|
|
453
|
+
}
|
|
454
|
+
function collectActiveRegistryGlobalMiddlewares(registry) {
|
|
455
|
+
const additions = [
|
|
456
|
+
...registry.globalMiddlewares,
|
|
457
|
+
...registry.middlewares.filter(contribution => contribution.global),
|
|
458
|
+
];
|
|
459
|
+
const active = new Map();
|
|
460
|
+
const mutations = (0, order_1.orderedPluginContributions)([
|
|
461
|
+
...additions.map(contribution => ({ ...contribution, kind: 'add' })),
|
|
462
|
+
...registry.middlewareRemovals.map(contribution => ({ ...contribution, kind: 'remove' })),
|
|
463
|
+
]);
|
|
464
|
+
for (const mutation of mutations) {
|
|
465
|
+
if (mutation.kind === 'remove') {
|
|
466
|
+
for (const name of mutation.names)
|
|
467
|
+
active.delete(name);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
active.set(mutation.name, mutation);
|
|
471
|
+
}
|
|
472
|
+
return [...active.values()];
|
|
473
|
+
}
|
|
474
|
+
function uniqueMiddlewareNames(middlewares) {
|
|
475
|
+
const names = [];
|
|
476
|
+
const seen = new Set();
|
|
477
|
+
for (const middleware of middlewares) {
|
|
478
|
+
const name = String(middleware);
|
|
479
|
+
if (seen.has(name))
|
|
480
|
+
continue;
|
|
481
|
+
seen.add(name);
|
|
482
|
+
names.push(name);
|
|
483
|
+
}
|
|
484
|
+
return names;
|
|
485
|
+
}
|
|
486
|
+
function suppressesDefault(flag, key) {
|
|
487
|
+
return flag === true || (Array.isArray(flag) && flag.includes(key));
|
|
488
|
+
}
|
|
489
|
+
function composeDefaults(target, defaults, contributions, userDefaults, keys) {
|
|
490
|
+
if (!target)
|
|
491
|
+
return;
|
|
492
|
+
const ordered = (0, order_1.orderedPluginContributions)(contributions);
|
|
493
|
+
for (const key of keys) {
|
|
494
|
+
const imperative = ordered.map(contribution => contribution.hooks?.[key]).filter(isFunction);
|
|
495
|
+
const additive = [...imperative];
|
|
496
|
+
const userHook = userDefaults?.[key];
|
|
497
|
+
if (!additive.length && typeof userHook !== 'function')
|
|
498
|
+
continue;
|
|
499
|
+
const suppressed = contributions.some(contribution => isFunction(contribution.hooks?.[key]) &&
|
|
500
|
+
suppressesDefault(contribution.suppressDefault, key));
|
|
501
|
+
const fallbackHook = defaults?.[key];
|
|
502
|
+
const base = isFunction(userHook)
|
|
503
|
+
? userHook
|
|
504
|
+
: suppressed
|
|
505
|
+
? undefined
|
|
506
|
+
: isFunction(fallbackHook)
|
|
507
|
+
? fallbackHook
|
|
508
|
+
: undefined;
|
|
509
|
+
const hooks = base ? [...additive, base] : additive;
|
|
510
|
+
if (hooks.length)
|
|
511
|
+
target[key] = composeHooks(hooks);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function composeCommandProps(target, defaults, contributions, userDefaults) {
|
|
515
|
+
if (!target)
|
|
516
|
+
return;
|
|
517
|
+
const pluginProps = contributions
|
|
518
|
+
.map(contribution => contribution.hooks?.props)
|
|
519
|
+
.filter((props) => isPlainObject(props));
|
|
520
|
+
const merged = (0, common_1.MergeOptions)({}, isPlainObject(defaults?.props) ? defaults.props : {}, ...pluginProps, isPlainObject(userDefaults?.props) ? userDefaults.props : {});
|
|
521
|
+
if (Object.keys(merged).length)
|
|
522
|
+
target.props = merged;
|
|
523
|
+
}
|
|
524
|
+
function composeHooks(hooks) {
|
|
525
|
+
return async (...args) => {
|
|
526
|
+
for (const hook of hooks)
|
|
527
|
+
await hook(...args);
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function collectPluginDefaultContributions(options, contributions, kind) {
|
|
531
|
+
return [
|
|
532
|
+
...options.flatMap(contribution => {
|
|
533
|
+
const hooks = contribution.fragment[kind]?.defaults;
|
|
534
|
+
if (!hooks)
|
|
535
|
+
return [];
|
|
536
|
+
return [
|
|
537
|
+
{
|
|
538
|
+
record: contribution.record,
|
|
539
|
+
kind,
|
|
540
|
+
hooks: hooks,
|
|
541
|
+
scope: contribution.scope,
|
|
542
|
+
order: contribution.order,
|
|
543
|
+
sequence: contribution.sequence,
|
|
544
|
+
},
|
|
545
|
+
];
|
|
546
|
+
}),
|
|
547
|
+
...contributions.filter(contribution => contribution.kind === kind),
|
|
548
|
+
];
|
|
549
|
+
}
|
|
550
|
+
function isFunction(value) {
|
|
551
|
+
return typeof value === 'function';
|
|
552
|
+
}
|
|
553
|
+
function isPlainObject(value) {
|
|
554
|
+
if (typeof value !== 'object' || value === null)
|
|
555
|
+
return false;
|
|
556
|
+
const prototype = Object.getPrototypeOf(value);
|
|
557
|
+
return prototype === Object.prototype || prototype === null;
|
|
558
|
+
}
|