@kanjijs/config 0.2.0-beta.1

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.
Files changed (3) hide show
  1. package/README.md +67 -0
  2. package/dist/index.js +1718 -0
  3. package/package.json +23 -0
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @kanjijs/config
2
+
3
+ Type-safe configuration module for Kanjijs Framework, powered by Zod.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @kanjijs/config zod dotenv
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### 1. Define your Config Schema
14
+ Create a Zod schema that represents your required environment variables.
15
+
16
+ ```typescript
17
+ // config.ts
18
+ import { z } from "zod";
19
+
20
+ export const AppConfig = z.object({
21
+ DATABASE_URL: z.string(),
22
+ PORT: z.coerce.number().default(3000),
23
+ NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
24
+ });
25
+
26
+ export type AppConfigType = z.infer<typeof AppConfig>;
27
+ ```
28
+
29
+ ### 2. Register ConfigModule
30
+ Import `ConfigModule` in your root `AppModule` using `.forRoot()`. Pass your Zod schema.
31
+
32
+ ```typescript
33
+ // app.module.ts
34
+ import { Module } from "@kanjijs/core";
35
+ import { ConfigModule } from "@kanjijs/config";
36
+ import { AppConfig } from "./config";
37
+
38
+ @Module({
39
+ imports: [
40
+ ConfigModule.forRoot({
41
+ schema: AppConfig,
42
+ envFilePath: ".env" // optional, default
43
+ })
44
+ ]
45
+ })
46
+ export class AppModule {}
47
+ ```
48
+
49
+ ### 3. Inject ConfigService
50
+ Inject `ConfigService` where needed. Pass the config type generic for auto-completion.
51
+
52
+ ```typescript
53
+ // user.service.ts
54
+ import { Injectable } from "@kanjijs/core";
55
+ import { ConfigService } from "@kanjijs/config";
56
+ import type { AppConfigType } from "./config";
57
+
58
+ @Injectable()
59
+ export class UserService {
60
+ constructor(private config: ConfigService<AppConfigType>) {}
61
+
62
+ getDbUrl() {
63
+ // Fully typed! Returns string.
64
+ return this.config.get("DATABASE_URL");
65
+ }
66
+ }
67
+ ```