@constatic/base 0.0.1-beta.11 → 0.0.1-beta.12

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.
@@ -2,14 +2,66 @@ import { type Client } from "discord.js";
2
2
  import { type BaseErrorHandler } from "./app.js";
3
3
  import { type CustomClientOptions } from "./client.js";
4
4
  export interface BootstrapOptions extends CustomClientOptions {
5
- token?: string;
5
+ /**
6
+ * The caller module's `import.meta`.
7
+ * Internally used for resolving file paths when dynamically loading modules.
8
+ */
6
9
  meta: ImportMeta;
10
+ /**
11
+ * The Discord bot token.
12
+ * If omitted, bootstrap will attempt to use:
13
+ * - `env.BOT_TOKEN`
14
+ * - `process.env.BOT_TOKEN`
15
+ */
16
+ token?: string;
17
+ /**
18
+ * A custom error handler that overrides the default one
19
+ * configured by `ConstaticApp`.
20
+ *
21
+ * If provided, all global errors such as:
22
+ * - `uncaughtException`
23
+ * - `unhandledRejection`
24
+ *
25
+ * will be handled by this function.
26
+ */
7
27
  errorHandler?: BaseErrorHandler;
28
+ /**
29
+ * A hook executed before loading the modules.
30
+ * Can be used to register services, prepare caches,
31
+ * validate dependencies, or modify the client before initialization.
32
+ */
8
33
  beforeLoad?(client: Client<boolean>): Promise<void>;
34
+ /**
35
+ * Additional glob patterns used to load application modules.
36
+ */
9
37
  modules?: string[];
38
+ /**
39
+ * Whether initialization logs should be displayed.
40
+ * Defaults to `true`.
41
+ */
10
42
  loadLogs?: boolean;
43
+ /**
44
+ * Custom environment variables that may complement or override
45
+ * values from `process.env`.
46
+ */
11
47
  env?: Record<string, any>;
12
48
  }
49
+ /**
50
+ *
51
+ * Bootstraps and initializes a Constatic application, creating the Discord client,
52
+ * loading modules, registering events, and applying global error handlers.
53
+ *
54
+ * @example
55
+ * import { bootstrap } from "@constatic/base";
56
+ *
57
+ * await bootstrap({ meta: import.meta });
58
+ *
59
+ * @example
60
+ * import { env } from "#env";
61
+ * import { bootstrap } from "@constatic/base";
62
+ *
63
+ * await bootstrap({ meta: import.meta, env });
64
+ */
13
65
  export declare function bootstrap(options: BootstrapOptions): Promise<{
14
66
  client: Client<boolean>;
15
67
  imports: import("./modules.js").ModuleImported[];
package/dist/client.d.ts CHANGED
@@ -1,3 +1,12 @@
1
1
  import { Client, type ClientOptions } from "discord.js";
2
2
  export type CustomClientOptions = Partial<ClientOptions>;
3
+ /**
4
+ * Creates and configures a Discord.js client instance integrated with ConstaticApp.
5
+ *
6
+ * This function initializes a `Client`, assigns the provided bot token, binds
7
+ * lifecycle events, and automatically wires command handlers, autocomplete
8
+ * handlers, and general interaction responders from the Constatic framework.
9
+ *
10
+ * The client will log a formatted startup message once it becomes ready.
11
+ */
3
12
  export declare function createClient(token: string, options: CustomClientOptions): Client<boolean>;
@@ -10,6 +10,29 @@ export interface SetupCreatorsOptions {
10
10
  responders?: Partial<BaseRespondersConfig>;
11
11
  events?: Partial<BaseEventsConfig>;
12
12
  }
13
+ /**
14
+ * Initializes the Constatic command/event/responder creation system.
15
+ *
16
+ * This function configures the Constatic application’s internal registries
17
+ * for commands, events, and responders, and returns a set of factory
18
+ * functions used to create each type of component.
19
+ *
20
+ * It also:
21
+ * - Applies optional default command permissions
22
+ * - Merges user-provided config into the ConstaticApp instance
23
+ * - Automatically injects `process.env.GUILD_ID` into guild-restricted commands
24
+ * - Ensures `"clientReady"` events always run once
25
+ *
26
+ * **Returned creators:**
27
+ * - `createCommand(data)` — Registers a new slash command (or other command type)
28
+ * - `createEvent(data)` — Registers a Discord.js event listener
29
+ * - `createResponder(data)` — Registers an interaction responder (buttons, modals, etc.)
30
+ *
31
+ * @example
32
+ * import { setupCreators } from "@constatic/base";
33
+ *
34
+ * export const { createCommand, createResponder, createEvent } = setupCreators();
35
+ */
13
36
  export declare function setupCreators(options?: SetupCreatorsOptions): {
14
37
  createCommand<T extends CommandType = ApplicationCommandType.ChatInput, P extends boolean = false, R = void>(data: CommandData<T, P, R>): Command<T, P, R>;
15
38
  createEvent: <EventName extends keyof ClientEvents>(data: EventData<EventName>) => Event<EventName>;
package/dist/env.d.ts CHANGED
@@ -1,5 +1,28 @@
1
1
  import type { StandardSchemaV1 } from "./utils/schema.js";
2
2
  type Schema = StandardSchemaV1;
3
3
  type Out<T extends Schema> = StandardSchemaV1.InferOutput<T>;
4
+ /**
5
+ * Validates the current process environment variables using a StandardSchema.
6
+ *
7
+ * This function executes the schema validation against `process.env`
8
+ * and ensures all required environment variables follow the expected shape.
9
+ * @example
10
+ * // "env.ts" — Using Zod
11
+ * import { z } from "zod";
12
+ * import { validateEnv } from "@constatic/base";
13
+ *
14
+ * export const env = await validateEnv(z.object({
15
+ * BOT_TOKEN: z.string("BOT_TOKEN is required").min(1)
16
+ * }).passthrough());
17
+ *
18
+ * @example
19
+ * // "env.ts" — Using ArkType
20
+ * import { type } from "arktype";
21
+ * import { validateEnv } from "@constatic/base";
22
+ *
23
+ * export const env = await validateEnv(type({
24
+ * BOT_TOKEN: "string > 0"
25
+ * }));
26
+ */
4
27
  export declare function validateEnv<T extends Schema>(schema: T): Promise<Out<T>>;
5
28
  export {};
package/dist/modules.d.ts CHANGED
@@ -2,4 +2,8 @@ export interface ModuleImported {
2
2
  module: any;
3
3
  filepath: string;
4
4
  }
5
+ /**
6
+ * Dynamically loads modules using glob patterns, returning each imported module
7
+ * along with its file path.
8
+ */
5
9
  export declare function loadModules(meta: ImportMeta, modules?: string[]): Promise<ModuleImported[]>;
package/dist/version.d.ts CHANGED
@@ -1 +1,7 @@
1
+ /**
2
+ * Represents the current lib version.
3
+ *
4
+ * The version follows semantic versioning (SemVer), typically in the format:
5
+ * `"MAJOR.MINOR.PATCH"` — for example: `"1.0.0"`.
6
+ */
1
7
  export declare const version: string;
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var version = "0.0.1-beta.11";
2
+ var version = "0.0.1-beta.12";
3
3
  export {
4
4
  version
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constatic/base",
3
- "version": "0.0.1-beta.11",
3
+ "version": "0.0.1-beta.12",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",