@saykit/carbon 0.9.0 → 0.10.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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Coverage](https://codecov.io/gh/k0d13/saykit/graph/badge.svg?flag=integration-carbon)](https://codecov.io/gh/k0d13/saykit?flags%5B0%5D=integration-carbon)
6
6
 
7
- Registers a shared `Say` with your Carbon client, helps command and component classes expose translated metadata, and adds locale-aware `interaction.say` and `guild.say` properties.
7
+ Registers a shared catalogue with your Carbon client, helps command and component classes expose translated metadata, and adds locale-aware `interaction.say` and `guild.say` properties.
8
8
 
9
9
  ## Install
10
10
 
@@ -17,12 +17,12 @@ pnpm add @saykit/carbon saykit @buape/carbon
17
17
  ```ts
18
18
  import { Client, Command, type CommandInteraction } from '@buape/carbon';
19
19
  import { SayPlugin, withSay } from '@saykit/carbon';
20
- import { type Say } from 'saykit';
21
- import say from './i18n.js';
20
+ import { type Catalogue } from 'saykit';
21
+ import catalogue from './i18n.js';
22
22
 
23
23
  class PingCommand extends withSay(Command) {
24
- constructor(say: Say) {
25
- super(say, (say) => ({
24
+ constructor(catalogue: Catalogue) {
25
+ super(catalogue, (say) => ({
26
26
  name: say`ping`,
27
27
  description: say`Ping the bot!`,
28
28
  }));
@@ -33,8 +33,8 @@ class PingCommand extends withSay(Command) {
33
33
  }
34
34
  }
35
35
 
36
- const client = new Client({/* options */}, { commands: [new PingCommand(say)] }, [
37
- new SayPlugin(say),
36
+ const client = new Client({/* options */}, { commands: [new PingCommand(catalogue)] }, [
37
+ new SayPlugin(catalogue),
38
38
  ]);
39
39
  ```
40
40
 
package/dist/index.d.mts CHANGED
@@ -1,13 +1,9 @@
1
1
  import { APIInteraction, BaseCommand, BaseComponent, Modal, Plugin } from "@buape/carbon";
2
- import { Say } from "saykit";
3
- //#region src/constants.d.ts
4
- declare const kSay: unique symbol;
5
- //#endregion
2
+ import { Catalogue, View } from "saykit";
6
3
  //#region src/extensions/base-interaction.d.ts
7
4
  declare module '@buape/carbon' {
8
5
  interface BaseInteraction<T extends APIInteraction> {
9
- get say(): Say;
10
- [kSay]: Say;
6
+ get say(): View;
11
7
  }
12
8
  }
13
9
  declare function applyBaseInteractionExtension(): () => void;
@@ -15,8 +11,7 @@ declare function applyBaseInteractionExtension(): () => void;
15
11
  //#region src/extensions/guild.d.ts
16
12
  declare module '@buape/carbon' {
17
13
  interface Guild {
18
- get say(): Say;
19
- [kSay]: Say;
14
+ get say(): View;
20
15
  }
21
16
  }
22
17
  declare function applyGuildExtension(): () => void;
@@ -29,10 +24,10 @@ type SayProps<T> = Pick<T, Extract<keyof T, Keys>>;
29
24
  * Enhances a {@link BaseCommand} subclass with support for localisation.
30
25
  *
31
26
  * @param Base Abstract command constructor to extend.
32
- * @returns A new constructor that accepts a {@link Say} instance, a
27
+ * @returns A new constructor that accepts a {@link Catalogue}, a
33
28
  * properties-mapping function, and the original constructor arguments.
34
29
  */
35
- declare function withSay<Args extends unknown[], Instance extends BaseCommand>(Base: AbstractConstructor<Args, Instance>): AbstractConstructor<[say: Say, properties: (say: Say) => SayProps<Instance>, ...args: Args], Instance & Partial<Record<Keys, unknown>>>;
30
+ declare function withSay<Args extends unknown[], Instance extends BaseCommand>(Base: AbstractConstructor<Args, Instance>): AbstractConstructor<[catalogue: Catalogue, properties: (say: View) => SayProps<Instance>, ...args: Args], Instance & Partial<Record<Keys, unknown>>>;
36
31
  /**
37
32
  * Enhances a {@link BaseComponent} or {@link Modal} subclass with
38
33
  * support for localisation.
@@ -44,21 +39,21 @@ declare function withSay<Args extends unknown[], Instance extends BaseComponent
44
39
  //#endregion
45
40
  //#region src/plugin.d.ts
46
41
  /**
47
- * A Carbon plugin that provides a singleton {@link Say} instance.
42
+ * A Carbon plugin that provides a singleton {@link Catalogue}.
48
43
  *
49
- * `SayPlugin` registers a {@link Say} instance globally and
50
- * applies interaction and guild-level extensions so that commands and
51
- * other handlers can access localisation utilities directly.
44
+ * `SayPlugin` registers a {@link Catalogue} globally and applies interaction and
45
+ * guild-level extensions, so that commands and other handlers can reach a view
46
+ * for their own locale directly.
52
47
  *
53
48
  * @example
54
49
  * ```ts
55
- * const say = new Say({ ... });
56
- * const client = new Client({ ... }, { ... }, [new SayPlugin(say)]);
50
+ * const catalogue = createCatalogue({ ... });
51
+ * const client = new Client({ ... }, { ... }, [new SayPlugin(catalogue)]);
57
52
  * ```
58
53
  */
59
54
  declare class SayPlugin extends Plugin {
60
55
  id: string;
61
- constructor(say: Say);
56
+ constructor(catalogue: Catalogue);
62
57
  }
63
58
  //#endregion
64
59
  export { SayPlugin, type applyBaseInteractionExtension, type applyGuildExtension, withSay };
package/dist/index.mjs CHANGED
@@ -38,12 +38,12 @@ function withSay(Base) {
38
38
  }
39
39
  function createSayCommand(Base) {
40
40
  class SayCommand extends Base {
41
- constructor(say, properties, ...args) {
41
+ constructor(catalogue, properties, ...args) {
42
42
  super(...args);
43
- const options = combineCommandOptions(Array.from(say).reduce((acc, [s, l]) => {
44
- acc[l] = properties(s);
43
+ const options = combineCommandOptions(Array.from(catalogue).reduce((acc, [locale, say]) => {
44
+ acc[locale] = properties(say);
45
45
  return acc;
46
- }, {}), say.locale);
46
+ }, {}), catalogue.locales[0]);
47
47
  Object.assign(this, options);
48
48
  }
49
49
  }
@@ -65,12 +65,9 @@ const kSay = Symbol.for("saykit.say");
65
65
  //#region src/extensions/base-interaction.ts
66
66
  function applyBaseInteractionExtension() {
67
67
  Object.defineProperty(BaseInteraction.prototype, "say", { get() {
68
- const say = Reflect.get(globalThis, kSay);
69
- if (!say) throw new Error("No `say` instance available");
70
- this[kSay] ??= say.clone();
71
- const locale = this[kSay].match([this.rawData.locale]);
72
- this[kSay].activate(locale);
73
- return this[kSay];
68
+ const catalogue = Reflect.get(globalThis, kSay);
69
+ if (!catalogue) throw new Error("No catalogue registered, add SayPlugin to your Carbon client");
70
+ return catalogue.locale(catalogue.match([this.rawData.locale]));
74
71
  } });
75
72
  return () => {
76
73
  Object.defineProperty(BaseInteraction.prototype, "say", { value: void 0 });
@@ -80,12 +77,9 @@ function applyBaseInteractionExtension() {
80
77
  //#region src/extensions/guild.ts
81
78
  function applyGuildExtension() {
82
79
  Object.defineProperty(Guild.prototype, "say", { get() {
83
- const say = Reflect.get(globalThis, kSay);
84
- if (!say) throw new Error("No `say` instance available");
85
- this[kSay] ??= say.clone();
86
- const locale = this[kSay].match([this.rawData.preferred_locale]);
87
- this[kSay].activate(locale);
88
- return this[kSay];
80
+ const catalogue = Reflect.get(globalThis, kSay);
81
+ if (!catalogue) throw new Error("No catalogue registered, add SayPlugin to your Carbon client");
82
+ return catalogue.locale(catalogue.match([this.rawData.preferred_locale]));
89
83
  } });
90
84
  return () => {
91
85
  Object.defineProperty(Guild.prototype, "say", { value: void 0 });
@@ -95,9 +89,9 @@ function applyGuildExtension() {
95
89
  //#region src/plugin.ts
96
90
  var SayPlugin = class extends Plugin {
97
91
  id = "saykit";
98
- constructor(say) {
92
+ constructor(catalogue) {
99
93
  super();
100
- Reflect.set(globalThis, kSay, say);
94
+ Reflect.set(globalThis, kSay, catalogue);
101
95
  applyBaseInteractionExtension();
102
96
  applyGuildExtension();
103
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saykit/carbon",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Carbon Discord framework integration for saykit",
5
5
  "keywords": [
6
6
  "bot",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@buape/carbon": "0.16.0",
40
- "saykit": "^0.9.0"
40
+ "saykit": "^0.10.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@buape/carbon": "*",