@constatic/base 0.0.1-beta.10 → 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.
- package/dist/bootstrap.d.ts +54 -5
- package/dist/client.d.ts +9 -0
- package/dist/creators/setup.d.ts +23 -0
- package/dist/env.d.ts +23 -0
- package/dist/modules.d.ts +7 -2
- package/dist/modules.js +10 -7
- package/dist/version.d.ts +6 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/bootstrap.d.ts
CHANGED
|
@@ -2,18 +2,67 @@ 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
|
-
|
|
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
|
-
imports:
|
|
16
|
-
module: any;
|
|
17
|
-
filepath: string;
|
|
18
|
-
}[];
|
|
67
|
+
imports: import("./modules.js").ModuleImported[];
|
|
19
68
|
}>;
|
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>;
|
package/dist/creators/setup.d.ts
CHANGED
|
@@ -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
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
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
|
+
*/
|
|
9
|
+
export declare function loadModules(meta: ImportMeta, modules?: string[]): Promise<ModuleImported[]>;
|
package/dist/modules.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
// src/modules.ts
|
|
2
2
|
import { glob } from "node:fs/promises";
|
|
3
|
-
import
|
|
3
|
+
import { join } from "node:path";
|
|
4
4
|
async function loadModules(meta, modules = []) {
|
|
5
|
-
const exclude = modules.filter((
|
|
5
|
+
const exclude = modules.filter((path) => path.charAt(0) == "!").map((path) => path.slice(1));
|
|
6
6
|
const filepaths = await Array.fromAsync(glob(modules, { cwd: meta.dirname, exclude }));
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const loadModules2 = [];
|
|
8
|
+
for (const path of filepaths) {
|
|
9
|
+
await import(join(meta.dirname, path)).then((imported) => loadModules2.push({
|
|
10
|
+
module: imported,
|
|
11
|
+
filepath: path
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
return loadModules2;
|
|
12
15
|
}
|
|
13
16
|
export {
|
|
14
17
|
loadModules
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED