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

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/app.js CHANGED
@@ -1,11 +1,11 @@
1
1
  // src/app.ts
2
- import { version } from "#package";
3
2
  import { version as djsVersion } from "discord.js";
4
3
  import { styleText } from "node:util";
5
4
  import { CommandManager } from "./creators/commands/manager.js";
6
5
  import { EventManager } from "./creators/events/manager.js";
7
6
  import { ResponderManager } from "./creators/responders/manager.js";
8
7
  import { baseErrorHandler } from "./error.js";
8
+ import { version } from "./version.js";
9
9
  var isBun = typeof Bun !== "undefined";
10
10
 
11
11
  class ConstaticApp {
@@ -8,11 +8,9 @@ export interface BootstrapOptions extends CustomClientOptions {
8
8
  beforeLoad?(client: Client<boolean>): Promise<void>;
9
9
  modules?: string[];
10
10
  loadLogs?: boolean;
11
+ env?: Record<string, any>;
11
12
  }
12
13
  export declare function bootstrap(options: BootstrapOptions): Promise<{
13
14
  client: Client<boolean>;
14
- imports: {
15
- module: any;
16
- filepath: string;
17
- }[];
15
+ imports: import("./modules.js").ModuleImported[];
18
16
  }>;
package/dist/bootstrap.js CHANGED
@@ -4,7 +4,7 @@ import { createClient } from "./client.js";
4
4
  import { ConstaticError } from "./error.js";
5
5
  import { loadModules } from "./modules.js";
6
6
  async function bootstrap(options) {
7
- const token = options.token ?? process.env.BOT_TOKEN;
7
+ const token = options.token ?? options.env?.BOT_TOKEN ?? process.env?.BOT_TOKEN;
8
8
  if (!token)
9
9
  throw new ConstaticError("The application token was not provided!");
10
10
  const app = ConstaticApp.getInstance();
@@ -86,7 +86,7 @@ export declare class Command<Type, Perm, Return> {
86
86
  readonly data: CommandData<Type, Perm, Return>;
87
87
  readonly modules: CommandModule[];
88
88
  constructor(data: CommandData<Type, Perm, Return>);
89
- group<ModuleReturn>(data: SubCommandGroupModuleData<Perm, Return, ModuleReturn>): GroupCommandModule<Type, Perm, Return, ModuleReturn>;
90
- subcommand<Return>(data: SubCommandModuleData<Perm, Return>): this;
89
+ group<ModuleReturn = Return>(data: SubCommandGroupModuleData<Perm, Return, ModuleReturn>): GroupCommandModule<Type, Perm, Return, ModuleReturn>;
90
+ subcommand<R = Return>(data: SubCommandModuleData<Perm, R>): this;
91
91
  }
92
92
  export {};
@@ -3,7 +3,7 @@ import { type BaseCommandsConfig, type BaseEventsConfig, type BaseRespondersConf
3
3
  import { Command, type CommandData, type CommandType } from "./commands/command.js";
4
4
  import { Event, type EventData } from "./events/event.js";
5
5
  import { Responder, type ResponderData, type ResponderType } from "./responders/responder.js";
6
- interface SetupCreatorsOptions {
6
+ export interface SetupCreatorsOptions {
7
7
  commands?: BaseCommandsConfig & {
8
8
  defaultMemberPermissions?: PermissionResolvable[];
9
9
  };
@@ -15,4 +15,3 @@ export declare function setupCreators(options?: SetupCreatorsOptions): {
15
15
  createEvent: <EventName extends keyof ClientEvents>(data: EventData<EventName>) => Event<EventName>;
16
16
  createResponder<Path extends string, const Types extends readonly ResponderType[], Parsed, Cache extends CacheType = CacheType>(data: ResponderData<Path, Types, Parsed, Cache>): Responder<Path, Types, Parsed, Cache>;
17
17
  };
18
- export {};
@@ -7,6 +7,8 @@ function setupCreators(options = {}) {
7
7
  const app = ConstaticApp.getInstance();
8
8
  app.config.commands = { ...options.commands ??= {} };
9
9
  app.config.commands.guilds ??= [];
10
+ app.config.responders = { ...options.responders ??= {} };
11
+ app.config.events = { ...options.events ??= {} };
10
12
  if (process.env.GUILD_ID?.length) {
11
13
  app.config.commands.guilds.push(process.env.GUILD_ID);
12
14
  }
package/dist/env.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { StandardSchemaV1 } from "./utils/schema.js";
2
+ type Schema = StandardSchemaV1;
3
+ type Out<T extends Schema> = StandardSchemaV1.InferOutput<T>;
4
+ export declare function validateEnv<T extends Schema>(schema: T): Promise<Out<T>>;
5
+ export {};
package/dist/env.js ADDED
@@ -0,0 +1,15 @@
1
+ // src/env.ts
2
+ import { format, styleText } from "node:util";
3
+ async function validateEnv(schema) {
4
+ const result = await schema["~standard"].validate(process.env);
5
+ if (result.issues) {
6
+ console.log(result.issues.map((issue) => format(styleText("red", "✖︎ ENV VAR %s ➜ %s"), styleText("bold", issue.path?.join(".") ?? ""), styleText("gray", issue.message))).join(`
7
+ `));
8
+ process.exit(1);
9
+ }
10
+ console.log(styleText("dim", "☰ Environment variables validated ✓"));
11
+ return result.value;
12
+ }
13
+ export {
14
+ validateEnv
15
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export declare const version: string;
2
1
  export * from "./bootstrap.js";
3
2
  export * from "./creators/index.js";
3
+ export * from "./env.js";
4
+ export * from "./version.js";
package/dist/index.js CHANGED
@@ -1,9 +1,5 @@
1
1
  // src/index.ts
2
- import pkg from "../package.json";
3
-
4
2
  export * from "./bootstrap.js";
5
3
  export * from "./creators/index.js";
6
- var version = pkg.version;
7
- export {
8
- version
9
- };
4
+ export * from "./env.js";
5
+ export * from "./version.js";
package/dist/modules.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export declare function loadModules(meta: ImportMeta, modules?: string[]): Promise<{
1
+ export interface ModuleImported {
2
2
  module: any;
3
3
  filepath: string;
4
- }[]>;
4
+ }
5
+ export declare function loadModules(meta: ImportMeta, modules?: string[]): Promise<ModuleImported[]>;
package/dist/modules.js CHANGED
@@ -1,13 +1,17 @@
1
1
  // src/modules.ts
2
2
  import { glob } from "node:fs/promises";
3
+ import { join } from "node:path";
3
4
  async function loadModules(meta, modules = []) {
4
- const exclude = modules.filter((path) => path.startsWith("!")).map((path) => path.slice(1));
5
+ const exclude = modules.filter((path) => path.charAt(0) == "!").map((path) => path.slice(1));
5
6
  const filepaths = await Array.fromAsync(glob(modules, { cwd: meta.dirname, exclude }));
6
- const promises = filepaths.map((filepath) => import(meta.resolve(filepath)).then((imported) => ({
7
- module: imported,
8
- filepath
9
- })));
10
- return Promise.all(promises);
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;
11
15
  }
12
16
  export {
13
17
  loadModules
@@ -0,0 +1,56 @@
1
+ /** The Standard Schema interface. */
2
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
3
+ /** The Standard Schema properties. */
4
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
5
+ }
6
+ export declare namespace StandardSchemaV1 {
7
+ /** The Standard Schema properties interface. */
8
+ export interface Props<Input = unknown, Output = Input> {
9
+ /** The version number of the standard. */
10
+ readonly version: 1;
11
+ /** The vendor name of the schema library. */
12
+ readonly vendor: string;
13
+ /** Validates unknown input values. */
14
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
15
+ /** Inferred types associated with the schema. */
16
+ readonly types?: Types<Input, Output> | undefined;
17
+ }
18
+ /** The result interface of the validate function. */
19
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
20
+ /** The result interface if validation succeeds. */
21
+ export interface SuccessResult<Output> {
22
+ /** The typed output value. */
23
+ readonly value: Output;
24
+ /** The non-existent issues. */
25
+ readonly issues?: undefined;
26
+ }
27
+ /** The result interface if validation fails. */
28
+ export interface FailureResult {
29
+ /** The issues of failed validation. */
30
+ readonly issues: ReadonlyArray<Issue>;
31
+ }
32
+ /** The issue interface of the failure output. */
33
+ export interface Issue {
34
+ /** The error message of the issue. */
35
+ readonly message: string;
36
+ /** The path of the issue, if any. */
37
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
38
+ }
39
+ /** The path segment interface of the issue. */
40
+ export interface PathSegment {
41
+ /** The key representing a path segment. */
42
+ readonly key: PropertyKey;
43
+ }
44
+ /** The Standard Schema types interface. */
45
+ export interface Types<Input = unknown, Output = Input> {
46
+ /** The input type of the schema. */
47
+ readonly input: Input;
48
+ /** The output type of the schema. */
49
+ readonly output: Output;
50
+ }
51
+ /** Infers the input type of a Standard Schema. */
52
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
53
+ /** Infers the output type of a Standard Schema. */
54
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
55
+ export {};
56
+ }
File without changes
@@ -0,0 +1 @@
1
+ export declare const version: string;
@@ -0,0 +1,5 @@
1
+ // src/version.ts
2
+ var version = "0.0.1-beta.11";
3
+ export {
4
+ version
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constatic/base",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.11",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,16 +18,19 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@constatic/config": "*",
21
+ "@standard-schema/spec": "^1.0.0",
21
22
  "typescript": "^5.9.3"
22
23
  },
23
24
  "exports": {
24
25
  ".": {
25
26
  "import": "./dist/index.js",
26
27
  "types": "./dist/index.d.ts"
27
- }
28
+ },
29
+ "./tsconfig": "./tsconfig/base.json"
28
30
  },
29
31
  "files": [
30
- "dist"
32
+ "dist",
33
+ "tsconfig"
31
34
  ],
32
35
  "homepage": "https://constatic-docs.vercel.app",
33
36
  "imports": {
@@ -38,6 +41,7 @@
38
41
  "scripts": {
39
42
  "typegen": "tsc",
40
43
  "build": "bun run ./build.ts",
44
+ "prepublish": "bun run build",
41
45
  "dev": "bun run ./playground/index.ts"
42
46
  },
43
47
  "peerDependencies": {
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://www.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "esModuleInterop": true,
5
+ "forceConsistentCasingInFileNames": true,
6
+ "skipLibCheck": true,
7
+ "resolveJsonModule": true,
8
+ "strict": true,
9
+
10
+ "lib": ["ESNext"],
11
+ "target": "ESNext",
12
+ "module": "NodeNext",
13
+ "moduleResolution": "NodeNext",
14
+
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noImplicitReturns": true,
18
+ "noImplicitOverride": true,
19
+ "noEmitOnError": true,
20
+ }
21
+ }