@seedcord/core 0.1.0-next.0 → 0.1.0-next.2

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.
@@ -1 +1,102 @@
1
- export { };
1
+ import { C as BuilderComponent, a as CustomIdField, c as pickNotice, g as GateContextBase, h as Gate, i as prefixOf, l as GateFitsWith, n as CustomId, o as DecodedParams, p as Notice, r as decodeFor, t as AnyCustomId, x as CommandMeta } from "./CustomId-Ddwg48VY.mjs";
2
+ import { BotColor, EpochMs, ReplyResponse } from "@seedcord/types";
3
+
4
+ //#region src/components/botColorHolder.d.ts
5
+ declare function setBotColor(color: BotColor | undefined): void;
6
+ //#endregion
7
+ //#region src/gates/runGates.d.ts
8
+ /**
9
+ * Runs each gate's check in order, so the first refusal propagates to the dispatcher boundary. An effect
10
+ * gate's commit runs once the whole set passes.
11
+ */
12
+ declare function runGates(gates: readonly Gate<GateContextBase>[], ctx: GateContextBase): Promise<void>;
13
+ declare function runHandlerGates(handlerCtor: object, ctx: GateContextBase): Promise<void>;
14
+ //#endregion
15
+ //#region src/notices/index.d.ts
16
+ declare abstract class GateNotice extends Notice {
17
+ render(): ReplyResponse;
18
+ }
19
+ declare class NotOwner extends GateNotice {
20
+ constructor(message?: string);
21
+ }
22
+ declare class NotInGuild extends GateNotice {
23
+ constructor(message?: string);
24
+ }
25
+ declare class NotInDm extends GateNotice {
26
+ constructor(message?: string);
27
+ }
28
+ declare class OnCooldown extends GateNotice {
29
+ readonly resetAt: EpochMs;
30
+ constructor(resetAt: EpochMs, message?: string);
31
+ }
32
+ declare class NotAllowed extends Notice {
33
+ constructor();
34
+ render(): ReplyResponse;
35
+ }
36
+ declare class NeedsAny extends Notice {
37
+ private readonly summaries;
38
+ constructor(summaries: readonly string[]);
39
+ render(): ReplyResponse;
40
+ }
41
+ //#endregion
42
+ //#region src/metadataKeys.d.ts
43
+ declare enum InteractionRoutes {
44
+ Slash = "slash",
45
+ Button = "button",
46
+ Modal = "modal",
47
+ StringMenu = "stringMenu",
48
+ UserMenu = "userMenu",
49
+ RoleMenu = "roleMenu",
50
+ ChannelMenu = "channelMenu",
51
+ MentionableMenu = "mentionableMenu",
52
+ MessageContextMenu = "messageContextMenu",
53
+ UserContextMenu = "userContextMenu",
54
+ Autocomplete = "autocomplete"
55
+ }
56
+ declare const InteractionMetadataKey: unique symbol;
57
+ declare const InteractionRouteKeys: Record<InteractionRoutes, symbol>;
58
+ declare const MiddlewareMetadataKey: unique symbol;
59
+ declare const EventMetadataKey: unique symbol;
60
+ declare const CommandMetadataKey: unique symbol;
61
+ declare const GatedMetadataKey: unique symbol;
62
+ declare const SubscribeMetadataKey: unique symbol;
63
+ //#endregion
64
+ //#region src/stops/NoticeCard.d.ts
65
+ /**
66
+ * Built fresh inside a {@link Notice}'s `render` to back its ComponentsV2 reply. The title renders as
67
+ * an h3 line with the description on the next line.
68
+ */
69
+ declare class NoticeCard extends BuilderComponent<'container'> {
70
+ constructor(description: string, title?: string);
71
+ }
72
+ //#endregion
73
+ //#region src/customId/routing.d.ts
74
+ /**
75
+ * The route decorators store a handler's customId definitions here so the component base can decode
76
+ * against them at runtime.
77
+ *
78
+ * @internal
79
+ */
80
+ declare const ComponentDefsKey: unique symbol;
81
+ /**
82
+ * The phantom a component handler base carries. A route decorator constrains its argument to this, so
83
+ * passing different definitions to the decorator and the handler's generic is a compile error. Never set at runtime.
84
+ *
85
+ * @internal
86
+ */
87
+ interface HasComponentDefs<Defs extends readonly AnyCustomId[]> {
88
+ readonly __componentDefs?: Defs;
89
+ }
90
+ //#endregion
91
+ //#region src/pagination/cursor.d.ts
92
+ declare const PAGE_MAX = 1000000;
93
+ /** Page cursor for a paginator. */
94
+ type PageCursor<Prefix extends string> = CustomId<Prefix, {
95
+ page: CustomIdField<number>;
96
+ slot: CustomIdField<number>;
97
+ }>;
98
+ /** Build the page cursor for a paginator. */
99
+ declare function pageCursor<Prefix extends string>(prefix: Prefix): PageCursor<Prefix>;
100
+ //#endregion
101
+ export { type AnyCustomId, type CommandMeta, CommandMetadataKey, ComponentDefsKey, type DecodedParams, EventMetadataKey, type GateFitsWith, GateNotice, GatedMetadataKey, type HasComponentDefs, InteractionMetadataKey, InteractionRouteKeys, InteractionRoutes, MiddlewareMetadataKey, NeedsAny, NotAllowed, NotInDm, NotInGuild, NotOwner, NoticeCard, OnCooldown, PAGE_MAX, type PageCursor, SubscribeMetadataKey, decodeFor, pageCursor, pickNotice, prefixOf, runGates, runHandlerGates, setBotColor };
102
+ //# sourceMappingURL=internal.index.d.mts.map
@@ -1 +1,43 @@
1
- export { };
1
+ import { C as EventMetadataKey, D as InteractionRoutes, E as InteractionRouteKeys, O as MiddlewareMetadataKey, S as CommandMetadataKey, T as InteractionMetadataKey, _ as NoticeCard, a as discardCommits, b as setBotColor, c as runCheck, d as NeedsAny, f as NotAllowed, g as OnCooldown, h as NotOwner, i as pickNotice, k as SubscribeMetadataKey, l as runCommits, m as NotInGuild, n as decodeFor, p as NotInDm, r as prefixOf, t as CustomId, u as GateNotice, w as GatedMetadataKey } from "./CustomId-Bq6WagiA.mjs";
2
+
3
+ //#region src/gates/runGates.ts
4
+ /**
5
+ * Runs each gate's check in order, so the first refusal propagates to the dispatcher boundary. An effect
6
+ * gate's commit runs once the whole set passes.
7
+ */
8
+ async function runGates(gates, ctx) {
9
+ try {
10
+ for (const gate of gates) await runCheck(gate, ctx);
11
+ await runCommits(ctx);
12
+ } finally {
13
+ discardCommits(ctx);
14
+ }
15
+ }
16
+ async function runHandlerGates(handlerCtor, ctx) {
17
+ const gates = Reflect.getMetadata(GatedMetadataKey, handlerCtor);
18
+ if (!gates) return;
19
+ await runGates(gates, ctx);
20
+ }
21
+
22
+ //#endregion
23
+ //#region src/customId/routing.ts
24
+ /**
25
+ * The route decorators store a handler's customId definitions here so the component base can decode
26
+ * against them at runtime.
27
+ *
28
+ * @internal
29
+ */
30
+ const ComponentDefsKey = Symbol("seedcord:customId:componentDefs");
31
+
32
+ //#endregion
33
+ //#region src/pagination/cursor.ts
34
+ const PAGE_MAX = 1e6;
35
+ const SLOT_MAX = 4;
36
+ /** Build the page cursor for a paginator. */
37
+ function pageCursor(prefix) {
38
+ return new CustomId(prefix).int("page", 0, PAGE_MAX).int("slot", 0, SLOT_MAX);
39
+ }
40
+
41
+ //#endregion
42
+ export { CommandMetadataKey, ComponentDefsKey, EventMetadataKey, GateNotice, GatedMetadataKey, InteractionMetadataKey, InteractionRouteKeys, InteractionRoutes, MiddlewareMetadataKey, NeedsAny, NotAllowed, NotInDm, NotInGuild, NotOwner, NoticeCard, OnCooldown, PAGE_MAX, SubscribeMetadataKey, decodeFor, pageCursor, pickNotice, prefixOf, runGates, runHandlerGates, setBotColor };
43
+ //# sourceMappingURL=internal.index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.index.mjs","names":[],"sources":["../src/gates/runGates.ts","../src/customId/routing.ts","../src/pagination/cursor.ts"],"sourcesContent":["import { GatedMetadataKey } from '@src/metadataKeys';\n\nimport { discardCommits, runCheck, runCommits } from './effects';\n\nimport type { Gate, GateContextBase } from './Gate';\n\n/**\n * Runs each gate's check in order, so the first refusal propagates to the dispatcher boundary. An effect\n * gate's commit runs once the whole set passes.\n */\nexport async function runGates(gates: readonly Gate<GateContextBase>[], ctx: GateContextBase): Promise<void> {\n try {\n for (const gate of gates) {\n await runCheck(gate, ctx);\n }\n await runCommits(ctx);\n } finally {\n discardCommits(ctx);\n }\n}\n\n// dispatchers call this before execute, inside the boundary, so a refusal renders or drops\nexport async function runHandlerGates(handlerCtor: object, ctx: GateContextBase): Promise<void> {\n // justified: getMetadata returns any, and this key only ever stores the @Gated gate array\n const gates = Reflect.getMetadata(GatedMetadataKey, handlerCtor) as readonly Gate<GateContextBase>[] | undefined;\n if (!gates) return;\n await runGates(gates, ctx);\n}\n","import type { AnyCustomId } from './CustomId';\n\n/**\n * The route decorators store a handler's customId definitions here so the component base can decode\n * against them at runtime.\n *\n * @internal\n */\nexport const ComponentDefsKey = Symbol('seedcord:customId:componentDefs');\n\n/**\n * The phantom a component handler base carries. A route decorator constrains its argument to this, so\n * passing different definitions to the decorator and the handler's generic is a compile error. Never set at runtime.\n *\n * @internal\n */\nexport interface HasComponentDefs<Defs extends readonly AnyCustomId[]> {\n readonly __componentDefs?: Defs;\n}\n","import { CustomId } from '@customId/CustomId';\n\nimport type { CustomIdField } from '@customId/Field';\n\n// Included in the layout hash so it is fixed per prefix. Reducing it marks every active button as StaleCustomId.\n// @internal\nexport const PAGE_MAX = 1_000_000;\n\n// Discord rejects a message with duplicate custom_ids, and two controls can target the same page (first and\n// prev both hit 0), so each control uses a distinct slot.\n// @internal\nconst SLOT_MAX = 4;\n\n/** Page cursor for a paginator. */\nexport type PageCursor<Prefix extends string> = CustomId<\n Prefix,\n { page: CustomIdField<number>; slot: CustomIdField<number> }\n>;\n\n/** Build the page cursor for a paginator. */\nexport function pageCursor<Prefix extends string>(prefix: Prefix): PageCursor<Prefix> {\n return new CustomId(prefix).int('page', 0, PAGE_MAX).int('slot', 0, SLOT_MAX);\n}\n"],"mappings":";;;;;;;AAUA,eAAsB,SAAS,OAAyC,KAAqC;CACzG,IAAI;EACA,KAAK,MAAM,QAAQ,OACf,MAAM,SAAS,MAAM,GAAG;EAE5B,MAAM,WAAW,GAAG;CACxB,UAAU;EACN,eAAe,GAAG;CACtB;AACJ;AAGA,eAAsB,gBAAgB,aAAqB,KAAqC;CAE5F,MAAM,QAAQ,QAAQ,YAAY,kBAAkB,WAAW;CAC/D,IAAI,CAAC,OAAO;CACZ,MAAM,SAAS,OAAO,GAAG;AAC7B;;;;;;;;;;ACnBA,MAAa,mBAAmB,OAAO,iCAAiC;;;;ACFxE,MAAa,WAAW;AAKxB,MAAM,WAAW;;AASjB,SAAgB,WAAkC,QAAoC;CAClF,OAAO,IAAI,SAAS,MAAM,CAAC,CAAC,IAAI,QAAQ,GAAG,QAAQ,CAAC,CAAC,IAAI,QAAQ,GAAG,QAAQ;AAChF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@seedcord/core",
3
3
  "type": "module",
4
- "version": "0.1.0-next.0",
4
+ "version": "0.1.0-next.2",
5
5
  "description": "Transport-agnostic core for Seedcord bots",
6
6
  "repository": {
7
7
  "type": "git",
@@ -38,10 +38,21 @@
38
38
  "LICENSE"
39
39
  ],
40
40
  "peerDependencies": {
41
+ "reflect-metadata": "^0.2.2",
41
42
  "typescript": "^6.0.3"
42
43
  },
44
+ "dependencies": {
45
+ "@discordjs/builders": "^1.14.1",
46
+ "discord-api-types": "^0.38.49",
47
+ "@seedcord/errors": "0.3.0-next.2",
48
+ "@seedcord/types": "0.8.0-next.3",
49
+ "@seedcord/utils": "0.8.0-next.3"
50
+ },
43
51
  "devDependencies": {
44
- "@seedcord/eslint-config": "1.5.0-next.0",
52
+ "reflect-metadata": "^0.2.2",
53
+ "type-fest": "^5.7.0",
54
+ "@seedcord/eslint-config": "1.5.0-next.2",
55
+ "@seedcord/rate-limiter": "0.1.0-next.0",
45
56
  "@seedcord/tsconfig": "2.0.1",
46
57
  "@seedcord/tsdown-config": "2.0.1"
47
58
  },