@seedcord/core 0.12.0-next.0 → 0.12.0-next.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.
Files changed (41) hide show
  1. package/README.md +3 -3
  2. package/dist/{Bus-W1K-uMeO.mjs → Bus-VJw-QpoY.mjs} +110 -54
  3. package/dist/Bus-VJw-QpoY.mjs.map +1 -0
  4. package/dist/{CoordinatedShutdown-BVtNNSsF.d.mts → CoordinatedShutdown-fPKLWjc5.d.mts} +2 -2
  5. package/dist/{CoordinatedStartup-DA3gW8op.mjs → CoordinatedStartup-Zw_Lk7Zk.mjs} +3 -3
  6. package/dist/{CoordinatedStartup-DA3gW8op.mjs.map → CoordinatedStartup-Zw_Lk7Zk.mjs.map} +1 -1
  7. package/dist/HmrModuleHandler-Btgu8r96.mjs +165 -0
  8. package/dist/HmrModuleHandler-Btgu8r96.mjs.map +1 -0
  9. package/dist/{PluginHost-DWBgBS6Q.d.mts → PluginHost-DFnkIldj.d.mts} +10 -9
  10. package/dist/{PluginHost-CYe-UVpp.mjs → PluginHost-DTtxWRiL.mjs} +4 -4
  11. package/dist/PluginHost-DTtxWRiL.mjs.map +1 -0
  12. package/dist/{PluginLifecycle-DdwRzcDj.mjs → PluginLifecycle-hx5zUc-P.mjs} +4 -4
  13. package/dist/PluginLifecycle-hx5zUc-P.mjs.map +1 -0
  14. package/dist/{ServerHost-whpI0h4d.d.mts → ServerHost-B5o3ScCF.d.mts} +3 -3
  15. package/dist/{ServerHost-DHg-Y2_q.mjs → ServerHost-CDaEDR4C.mjs} +4 -4
  16. package/dist/{ServerHost-DHg-Y2_q.mjs.map → ServerHost-CDaEDR4C.mjs.map} +1 -1
  17. package/dist/hmr.index.d.mts +20 -20
  18. package/dist/hmr.index.mjs +1 -1
  19. package/dist/{index-Boo33hh3.d.mts → index-DGHng1IN.d.mts} +108 -193
  20. package/dist/index.d.mts +221 -74
  21. package/dist/index.mjs +222 -103
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/internal.index.d.mts +204 -82
  24. package/dist/internal.index.mjs +572 -73
  25. package/dist/internal.index.mjs.map +1 -1
  26. package/dist/node-internal.index.d.mts +4 -3
  27. package/dist/node-internal.index.mjs +3 -3
  28. package/dist/node.index.d.mts +2 -2
  29. package/dist/node.index.mjs +4 -4
  30. package/dist/{phases-Dojnr-ng.d.mts → phases-C2QCSqRu.d.mts} +60 -50
  31. package/dist/plugin.index.d.mts +1 -1
  32. package/dist/plugin.index.mjs +1 -1
  33. package/dist/{subscribers-D4_HZcgw.mjs → subscribers-CGuVjbrg.mjs} +139 -253
  34. package/dist/subscribers-CGuVjbrg.mjs.map +1 -0
  35. package/package.json +10 -9
  36. package/dist/Bus-W1K-uMeO.mjs.map +0 -1
  37. package/dist/HmrModuleHandler-BMD7dg8N.mjs +0 -162
  38. package/dist/HmrModuleHandler-BMD7dg8N.mjs.map +0 -1
  39. package/dist/PluginHost-CYe-UVpp.mjs.map +0 -1
  40. package/dist/PluginLifecycle-DdwRzcDj.mjs.map +0 -1
  41. package/dist/subscribers-D4_HZcgw.mjs.map +0 -1
@@ -34,7 +34,7 @@ import { Constructor, Jsonify, Simplify } from "type-fest";
34
34
  * super(`balance ${balance} is below the cost`);
35
35
  * }
36
36
  *
37
- * render(_ctx: RenderContext): ReplyResponse {
37
+ * override render(_ctx: RenderContext): ReplyResponse {
38
38
  * return { components: [new TooPoorCard(this.balance).component] };
39
39
  * }
40
40
  * }
@@ -59,7 +59,7 @@ declare abstract class Notice extends Error {
59
59
  */
60
60
  ephemeral: boolean;
61
61
  /**
62
- * A short one-line reason. When every arm of an {@link or} gate refuses and each one sets this, `or`
62
+ * A short one-line reason. When every gate in an {@link or} refuses and each one sets this, `or`
63
63
  * throws a refusal listing them under `You need to meet at least one of these:`. Write a verb phrase that
64
64
  * finishes that line, for example, "be the bot owner".
65
65
  */
@@ -67,10 +67,27 @@ declare abstract class Notice extends Error {
67
67
  protected constructor(message: string, options?: ErrorOptions);
68
68
  /**
69
69
  * Builds what the user sees. Called fresh each time the denial is shown, so the builders are new
70
- * and the bot color resolves at render time.
70
+ * and the bot color resolves at render time. By default it returns seedcord's refusal card with the message as
71
+ * its text. Override it to show your own components.
71
72
  */
72
- abstract render(ctx: RenderContext): ReplyResponse;
73
+ render(_ctx: RenderContext): ReplyResponse;
73
74
  }
75
+ /**
76
+ * A Notice class that seedcord constructs and throws in place of a default refusal. It passes the data that
77
+ * refusal carries, like the retry time for `Cooldown` or the subject and permission names for a permission check.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * class OwnersOnly extends Notice {
82
+ * public constructor() {
83
+ * super('Owners only.');
84
+ * }
85
+ * }
86
+ *
87
+ * OwnerOnly({ notice: OwnersOnly });
88
+ * ```
89
+ */
90
+ type NoticeConstructor<Args extends unknown[] = []> = Constructor<Notice, Args>;
74
91
  //#endregion
75
92
  //#region src/metadataKeys.d.ts
76
93
  /**
@@ -104,16 +121,42 @@ declare const WebhookUrlMetadataKey: unique symbol;
104
121
  declare const InteractionRouteKeys: Record<InteractionKind, symbol>;
105
122
  //#endregion
106
123
  //#region src/dispatch/DispatchContext.d.ts
107
- /** State shared by middleware and handlers during one dispatch. */
108
- declare class DispatchContext implements DispatchBag {
124
+ type DispatchKind = `${InteractionKind}` | 'event';
125
+ type InteractionDispatch = DispatchContext<InteractionKind>;
126
+ /**
127
+ * State shared by middleware, gates, and handlers during one dispatch.
128
+ *
129
+ * @typeParam Kind - What started this dispatch, an interaction kind or `event`.
130
+ */
131
+ declare class DispatchContext<Kind extends DispatchKind = DispatchKind> implements DispatchBag {
132
+ /** What started this dispatch, an interaction kind or `event`. */
133
+ readonly kind: Kind;
134
+ /**
135
+ * The slash path, context menu name, custom-ID prefix, or event name that started this dispatch.
136
+ * For a custom ID that seedcord didn't make, it can be empty or a cut-off piece of that ID.
137
+ */
138
+ readonly route: string;
139
+ /** True when this route doesn't have a registered handler. */
140
+ readonly fallback: boolean;
109
141
  private readonly state;
110
142
  readonly id: `${string}-${string}-${string}-${string}-${string}`;
143
+ constructor(
144
+ /** What started this dispatch, an interaction kind or `event`. */
145
+ kind: Kind,
146
+ /**
147
+ * The slash path, context menu name, custom-ID prefix, or event name that started this dispatch.
148
+ * For a custom ID that seedcord didn't make, it can be empty or a cut-off piece of that ID.
149
+ */
150
+ route: string,
151
+ /** True when this route doesn't have a registered handler. */
152
+ fallback?: boolean);
111
153
  /**
112
154
  * The dispatch identifier, such as `slash:search/docs`, `button:approve`, or `event:messageCreate`.
113
155
  * Component identifiers contain the custom-ID prefix without encoded params.
114
156
  */
115
- readonly routeId: string;
116
- constructor(routeId: string);
157
+ get routeId(): string;
158
+ /** The {@link routeId} of the handler's own route. It's `null` on an event and on the unhandled default. */
159
+ get declaredRoute(): string | null;
117
160
  set<Key extends keyof DispatchState>(key: Key, value: DispatchState[Key]): void;
118
161
  get<Key extends keyof DispatchState>(key: Key): DispatchState[Key] | undefined;
119
162
  /**
@@ -198,7 +241,7 @@ type ConfiguredDriver = NonNullable<Config['kv']>;
198
241
  type JsonSafe<TValue> = TValue extends string | number | boolean | null | undefined ? TValue : TValue extends {
199
242
  toJSON(): unknown;
200
243
  } ? TValue : TValue extends ((...args: never[]) => unknown) ? never : TValue extends ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> ? never : TValue extends readonly (infer Item)[] ? readonly JsonSafe<Item>[] : TValue extends object ? { [K in keyof TValue]: JsonSafe<TValue[K]>; } : never;
201
- type CollectionName<TRecord> = unknown extends TRecord ? 'Pass the record type, like kv.collection<Profile>(name).' : [TRecord] extends [JsonSafe<TRecord>] ? string : 'This record type holds a value JSON cannot keep, like a function, Map, Set, or bigint.';
244
+ type CollectionName<TRecord> = unknown extends TRecord ? 'Pass the record type, like kv.collection<Profile>(name).' : [TRecord] extends [JsonSafe<TRecord>] ? string : 'This record type holds a value that JSON cannot keep, like a function, Map, Set, or bigint.';
202
245
  /**
203
246
  * The bot's key-value store, or one prefixed slice of it. `core.kv` holds your handlers' records. A
204
247
  * plugin's `this.kv` holds the plugin's.
@@ -292,7 +335,7 @@ interface EventFaultSource {
292
335
  readonly raw: unknown;
293
336
  }
294
337
  /**
295
- * The fields both `responseAttempted` arms carry.
338
+ * The fields both `responseAttempted` shapes carry.
296
339
  */
297
340
  interface AttemptedWrite {
298
341
  /** The dispatch this write belongs to, for joining against every other key it published. */
@@ -436,42 +479,11 @@ type PublishableKey = TypedExclude<SubscriptionKey, keyof DefaultSubscriptions>;
436
479
  type SubscriptionData<KeyOfSubscribers extends SubscriptionKey> = AllSubscriptions[KeyOfSubscribers];
437
480
  type SubscriptionTuples = { [K in SubscriptionKey]: [AllSubscriptions[K]]; };
438
481
  //#endregion
439
- //#region src/subscribers/Subscriber.d.ts
440
- /**
441
- * Abstract base class for handling application subscribers.
442
- *
443
- * Provides type-safe access to subscribers data and the core framework instance.
444
- * Extend this class to create custom subscriber handlers.
445
- *
446
- * @typeParam KeyOfSubscribers - The specific subscriber type this handler processes
447
- * @typeParam TCore - The transport's Core
448
- */
449
- declare abstract class Subscriber<KeyOfSubscribers extends SubscriptionKey, TCore extends CoreBase> {
450
- protected readonly data: AllSubscriptions[KeyOfSubscribers];
451
- protected readonly core: TCore;
452
- protected readonly logger: Logger;
453
- /**
454
- * Instantiates the subscriber with event data and core.
455
- *
456
- * @param data - The subscriber event data
457
- * @param core - The core framework instance
458
- */
459
- constructor(data: AllSubscriptions[KeyOfSubscribers], core: TCore);
460
- /**
461
- * Executes the subscriber handler logic.
462
- */
463
- abstract execute(): Promise<void>;
464
- }
465
- //#endregion
466
482
  //#region src/subscribers/Bus.d.ts
467
483
  /** @internal */
468
- type StoredSubscriberCtor = Constructor<Subscriber<SubscriptionKey, CoreBase>, never[]>;
469
- /** @internal */
470
- interface SubscriberRegistration {
471
- readonly keys: readonly SubscriptionKey[];
472
- readonly frequency: EventFrequency;
473
- readonly ctor: StoredSubscriberCtor;
474
- }
484
+ type StoredSubscriberCtor = Constructor<{
485
+ execute(): Promise<void>;
486
+ }, never[]>;
475
487
  declare const loggerSlot: unique symbol;
476
488
  /**
477
489
  * Registers and dispatches subscribers. Subscribers run on a programmatic or framework publish.
@@ -489,12 +501,12 @@ declare class Bus extends TypedEventEmitter<SubscriptionTuples> {
489
501
  /** @internal keep this inside start(). a bad webhook url thrown outside it never resets the singleton guard */
490
502
  [RegisterDefaults](): void;
491
503
  /** @internal */
492
- [RegisterSubscriber](registration: SubscriberRegistration): void;
504
+ [RegisterSubscriber](ctor: StoredSubscriberCtor): void;
493
505
  /** @internal */
494
506
  [UnregisterSubscriber](ctor: StoredSubscriberCtor, keys?: readonly SubscriptionKey[]): void;
495
507
  /** @internal */
496
508
  get [RegisteredCount](): number;
497
- /** @internal registration already dropped every reporter with no url set */
509
+ /** @internal registration already skipped every reporter with no url set */
498
510
  [VerifyWebhooks](): Promise<void>;
499
511
  private probeWebhook;
500
512
  /**
@@ -527,8 +539,6 @@ declare class Bus extends TypedEventEmitter<SubscriptionTuples> {
527
539
  private runSubscriber;
528
540
  }
529
541
  /** @internal */
530
- declare function registrationFor(ctor: StoredSubscriberCtor): SubscriberRegistration;
531
- /** @internal */
532
542
  declare function busLoggerOf(bus: Bus): Logger;
533
543
  //#endregion
534
544
  //#region src/interfaces/CoreBase.d.ts
@@ -587,5 +597,5 @@ declare enum ShutdownPhase {
587
597
  }
588
598
  type TaskShutdownPhase = Exclude<ShutdownPhase, ShutdownPhase.Release>;
589
599
  //#endregion
590
- export { RegisterSubscriber as A, EventMiddlewareMetadataKey as B, reportedWrite as C, sendTarget as D, checkAckLegality as E, Kv as F, InteractionRouteKeys as G, InteractionKind as H, KvCollection as I, WebhookUrlMetadataKey as J, MiddlewareKind as K, DispatchContext as L, UnregisterSubscriber as M, VerifyWebhooks as N, AckTrace as O, PublishDefault as P, CommandMetadataKey as R, ReplyTelemetry as S, ReplyMethod as T, InteractionMetadataKey as U, GatedMetadataKey as V, InteractionMiddlewareMetadataKey as W, Notice as Y, ResponseOutcome as _, Bus as a, SubscriptionKey as b, busLoggerOf as c, AttemptedWrite as d, DefaultSubscriptions as f, ResponseFailed as g, ResponseAttempt as h, CoreBase as i, RegisteredCount as j, RegisterDefaults as k, registrationFor as l, FaultSource as m, StartupPhase as n, StoredSubscriberCtor as o, DispatchOutcome as p, SubscribeMetadataKey as q, TaskShutdownPhase as r, SubscriberRegistration as s, ShutdownPhase as t, Subscriber as u, ResponseSent as v, AckState as w, Subscriptions as x, SubscriptionData as y, EventMetadataKey as z };
591
- //# sourceMappingURL=phases-Dojnr-ng.d.mts.map
600
+ export { RegisteredCount as A, EventMiddlewareMetadataKey as B, AckState as C, AckTrace as D, sendTarget as E, KvCollection as F, InteractionRouteKeys as G, InteractionKind as H, DispatchContext as I, WebhookUrlMetadataKey as J, MiddlewareKind as K, InteractionDispatch as L, VerifyWebhooks as M, PublishDefault as N, RegisterDefaults as O, Kv as P, CommandMetadataKey as R, reportedWrite as S, checkAckLegality as T, InteractionMetadataKey as U, GatedMetadataKey as V, InteractionMiddlewareMetadataKey as W, NoticeConstructor as X, Notice as Y, ResponseSent as _, Bus as a, Subscriptions as b, AllSubscriptions as c, DispatchOutcome as d, FaultSource as f, ResponseOutcome as g, ResponseFailed as h, CoreBase as i, UnregisterSubscriber as j, RegisterSubscriber as k, AttemptedWrite as l, ResponseAttempt as m, StartupPhase as n, StoredSubscriberCtor as o, InteractionFaultSource as p, SubscribeMetadataKey as q, TaskShutdownPhase as r, busLoggerOf as s, ShutdownPhase as t, DefaultSubscriptions as u, SubscriptionData as v, ReplyMethod as w, ReplyTelemetry as x, SubscriptionKey as y, EventMetadataKey as z };
601
+ //# sourceMappingURL=phases-C2QCSqRu.d.mts.map
@@ -1,4 +1,4 @@
1
1
  import { n as PluginTypes, t as Generated } from "./Generated-ByC53_A2.mjs";
2
- import { n as PluginHost, p as PluginLifecycleSpec, s as Plugin, u as PluginOptions } from "./PluginHost-DWBgBS6Q.mjs";
2
+ import { n as PluginHost, p as PluginLifecycleSpec, s as Plugin, u as PluginOptions } from "./PluginHost-DFnkIldj.mjs";
3
3
  import { HmrAware, HmrUpdateEvent } from "@seedcord/types";
4
4
  export { type Generated, type HmrAware, type HmrUpdateEvent, Plugin, PluginHost, type PluginLifecycleSpec, type PluginOptions, type PluginTypes };
@@ -1,3 +1,3 @@
1
- import { o as Plugin, t as PluginHost } from "./PluginHost-CYe-UVpp.mjs";
1
+ import { s as Plugin, t as PluginHost } from "./PluginHost-DTtxWRiL.mjs";
2
2
 
3
3
  export { Plugin, PluginHost };