@kanjijs/cli 0.2.0-beta.2 → 0.2.0-beta.20

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
@@ -15,6 +15,7 @@ bunx @kanjijs/cli <command>
15
15
  ## Commands
16
16
 
17
17
  ### `new <project-name>`
18
+
18
19
  Scaffolds a new Kanjijs project with a predefined directory structure (bun + typescript).
19
20
 
20
21
  ```bash
@@ -22,22 +23,43 @@ kanjijs new my-app
22
23
  ```
23
24
 
24
25
  Features included out-of-the-box:
25
- * **Hono + Bun** set up.
26
- * **Observability**: `@kanjijs/logger` (JSON logs) + Request ID propagation.
27
- * **Security**: Rate Limiting enabled by default via `@kanjijs/throttler`.
28
- * **DI & Decorators**: Ready to use `@Controller` and `@Inject`.
26
+
27
+ - **Hono + Bun** set up.
28
+ - **Observability**: `@kanjijs/logger` (JSON logs) + Request ID propagation.
29
+ - **Security**: Rate Limiting enabled by default via `@kanjijs/throttler`.
30
+ - **DI & Decorators**: Ready to use `@Controller` and `@Inject`.
29
31
 
30
32
  ### `g resource <name>`
31
- Generates a new Resource Module (Controller + Service + Module).
33
+
34
+ Generates a new Resource Module (Controller + Service + Module + Test).
32
35
 
33
36
  ```bash
34
37
  kanjijs g resource products
38
+ kanjijs g resource products --repository # With Repository Pattern
39
+ ```
40
+
41
+ - scaffolds `products.module.ts`, `products.controller.ts`, `products.service.ts`
42
+ - **Full CRUD**: Generates `findAll`, `findOne`, `create`, `update`, and `remove` endpoints and methods.
43
+ - **Auto-generates** `products.controller.spec.ts` for unit testing with mocks for all CRUD methods.
44
+ - **Auto-updates** `src/app.module.ts` to import the new module! 🚀
45
+
46
+ ### `g schema <name>`
47
+
48
+ Generates a new Drizzle ORM Table definition.
49
+
50
+ ```bash
51
+ # Default: src/database/schema/users.ts (and updates index.ts)
52
+ kanjijs g schema users
53
+
54
+ # Co-located: src/modules/users/schemas/users.ts
55
+ kanjijs g schema users --module users
35
56
  ```
36
57
 
37
- * scaffolds `products.module.ts`, `products.controller.ts`, `products.service.ts`
38
- * **Auto-updates** `src/app.module.ts` to import the new module! 🚀
58
+ - Creates a `pgTable` with default columns (`id`, `createdAt`, `updatedAt`).
59
+ - **Auto-updates** the central barrel file (`src/database/schema/index.ts`) to export the new schema.
39
60
 
40
61
  ### `dev`
62
+
41
63
  Starts the development server via Bun in watch mode.
42
64
 
43
65
  ```bash
@@ -50,24 +72,28 @@ PORT=4000 kanjijs dev
50
72
 
51
73
  To hack on the CLI itself:
52
74
 
53
- 1. Clone the repo and install dependencies.
54
- 2. Link the package globally:
75
+ 1. Clone the repo and install dependencies.
76
+ 2. Link the package globally:
77
+
55
78
  ```bash
56
79
  cd packages/cli
57
80
  npm link
58
81
  ```
59
- 3. Run the builder in watch mode:
82
+
83
+ 3. Run the builder in watch mode:
84
+
60
85
  ```bash
61
86
  bun run watch
62
87
  ```
63
- 4. In another terminal, test your changes:
88
+
89
+ 4. In another terminal, test your changes:
90
+
64
91
  ```bash
65
92
  kanjijs g resource users
66
93
  ```
67
94
 
68
-
69
-
70
95
  ### `openapi`
96
+
71
97
  Generates an `openapi.json` file by inspecting your application metadata at runtime.
72
98
 
73
99
  ```bash
@@ -75,6 +101,7 @@ kanjijs openapi --out openapi.json
75
101
  ```
76
102
 
77
103
  ### `client`
104
+
78
105
  Generates a Type-Safe Client SDK (TypeScript) from your `openapi.json`.
79
106
  Uses [openapi-typescript-codegen](https://github.com/ferdikoomen/openapi-typescript-codegen).
80
107
 
@@ -0,0 +1,4 @@
1
+ import { Command as CommanderCommand } from "commander";
2
+ export declare abstract class Command {
3
+ abstract load(program: CommanderCommand): void;
4
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class ClientCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class DevCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class GenerateCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class NewCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class OpenApiCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};
@@ -0,0 +1,4 @@
1
+ import { Command as CommanderCommand } from "commander";
2
+ export declare abstract class Command {
3
+ abstract load(program: CommanderCommand): void;
4
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class ClientCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class DevCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class GenerateCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class NewCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from "commander";
2
+ import { Command as BaseCommand } from "./base";
3
+ export declare class OpenApiCommand extends BaseCommand {
4
+ load(program: Command): void;
5
+ }
@@ -0,0 +1,27 @@
1
+ export type SchemaLike = unknown;
2
+ export interface ContractRequestSpec<T = SchemaLike> {
3
+ params?: T;
4
+ query?: T;
5
+ headers?: T;
6
+ cookies?: T;
7
+ body?: T;
8
+ }
9
+ export interface ContractResponseSpec<T = SchemaLike> {
10
+ [status: number]: T;
11
+ }
12
+ export interface ContractSpec<T = SchemaLike> {
13
+ request?: ContractRequestSpec<T>;
14
+ response?: ContractResponseSpec<T>;
15
+ }
16
+ export interface ValidatorAdapter<S = SchemaLike> {
17
+ parse<O = unknown>(schema: S, data: unknown): Promise<{
18
+ success: true;
19
+ data: O;
20
+ } | {
21
+ success: false;
22
+ issues: unknown[];
23
+ }>;
24
+ }
25
+ export declare class Contract {
26
+ static json<T = SchemaLike>(spec: ContractRequestSpec<T>): ContractSpec<T>;
27
+ }
@@ -0,0 +1,7 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ export interface RequestContext {
3
+ requestId: string;
4
+ [key: string]: any;
5
+ }
6
+ export declare const kanjijsContext: AsyncLocalStorage<RequestContext>;
7
+ export declare function getRequestId(): string | undefined;
@@ -0,0 +1,34 @@
1
+ import type { ContractSpec } from "@kanjijs/contracts";
2
+ import { type ModuleMetadata, type Token } from "./metadata";
3
+ /**
4
+ * @Module({ controllers: [...] })
5
+ */
6
+ export declare function Module(metadata: ModuleMetadata): ClassDecorator;
7
+ /**
8
+ * @Contract({ ... })
9
+ */
10
+ export declare function Contract(spec: ContractSpec): MethodDecorator;
11
+ /**
12
+ * @Controller('/users')
13
+ */
14
+ export declare function Controller(prefix?: string): ClassDecorator;
15
+ export declare function Injectable(): ClassDecorator;
16
+ export declare const Get: (path?: string) => MethodDecorator;
17
+ export declare const Post: (path?: string) => MethodDecorator;
18
+ export declare const Put: (path?: string) => MethodDecorator;
19
+ export declare const Delete: (path?: string) => MethodDecorator;
20
+ export declare const Patch: (path?: string) => MethodDecorator;
21
+ /**
22
+ * @Inject("DATABASE_CLIENT")
23
+ */
24
+ export declare function Inject(token: Token<unknown>): ParameterDecorator;
25
+ /**
26
+ * @Use(middleware1, middleware2)
27
+ * Attaches middlewares to a controller or method.
28
+ */
29
+ export declare function Use(...middlewares: unknown[]): MethodDecorator & ClassDecorator;
30
+ export declare const Body: (data?: string) => ParameterDecorator;
31
+ export declare const Query: (data?: string) => ParameterDecorator;
32
+ export declare const Param: (data?: string) => ParameterDecorator;
33
+ export declare const Headers: (data?: string) => ParameterDecorator;
34
+ export declare const Ctx: (data?: string) => ParameterDecorator;
@@ -0,0 +1,26 @@
1
+ import { type Constructor, type Token } from "../metadata";
2
+ import "reflect-metadata";
3
+ export declare class KanjijsIoC {
4
+ private static providers;
5
+ static register<T>(target: Constructor<T>): void;
6
+ static register<T>(token: Token<T>, provider: {
7
+ useValue?: T;
8
+ useClass?: Constructor<T>;
9
+ }): void;
10
+ static resolve<T>(target: Token<T>): T;
11
+ static clear(): void;
12
+ }
13
+ /**
14
+ * V2 STRICT CONTAINER
15
+ * Instance-based, no auto-registration, explicit visibility.
16
+ */
17
+ export declare class Container {
18
+ private providers;
19
+ register<T>(token: Token<T>, provider: {
20
+ useValue?: T;
21
+ useClass?: Constructor<T>;
22
+ useFactory?: (...args: unknown[]) => T;
23
+ inject?: Array<Token<unknown>>;
24
+ }): void;
25
+ resolve<T>(token: Token<T>): T;
26
+ }
@@ -0,0 +1,12 @@
1
+ import { type Constructor } from "../metadata";
2
+ import { Container } from "./container";
3
+ export declare class ModuleCompiler {
4
+ private nodes;
5
+ private globalExportedTokens;
6
+ compile(rootModule: Constructor): Container;
7
+ private scan;
8
+ private processProviders;
9
+ private validate;
10
+ private checkDependencies;
11
+ private registerProviders;
12
+ }
@@ -0,0 +1,3 @@
1
+ export interface ExceptionFilter<T = any, C = any> {
2
+ catch(exception: T, context: C): void | Promise<void> | any;
3
+ }
@@ -0,0 +1,7 @@
1
+ export declare class HttpException extends Error {
2
+ readonly response: string | object;
3
+ readonly status: number;
4
+ constructor(response: string | object, status: number);
5
+ getResponse(): string | object;
6
+ getStatus(): number;
7
+ }
@@ -0,0 +1,9 @@
1
+ export type { ContractRequestSpec, ContractResponseSpec, ContractSpec, SchemaLike, ValidatorAdapter, } from "@kanjijs/contracts";
2
+ export * from "./context";
3
+ export * from "./decorators";
4
+ export * from "./di/container";
5
+ export * from "./di/module-compiler";
6
+ export * from "./exceptions/exception.filter";
7
+ export * from "./exceptions/http.exception";
8
+ export * from "./metadata";
9
+ export declare const GLOBAL_MIDDLEWARE_TOKEN: unique symbol;
@@ -0,0 +1,64 @@
1
+ import type { ContractSpec } from "@kanjijs/contracts";
2
+ import "reflect-metadata";
3
+ export type Constructor<T = unknown> = new (...args: unknown[]) => T;
4
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
5
+ export type RouteParamType = "BODY" | "QUERY" | "PARAM" | "HEADERS" | "CONTEXT";
6
+ export interface RouteParamMetadata {
7
+ index: number;
8
+ type: RouteParamType;
9
+ data?: string;
10
+ }
11
+ export interface RouteMetadata {
12
+ method: HttpMethod;
13
+ path: string;
14
+ contract?: ContractSpec;
15
+ middlewares?: unknown[];
16
+ params?: RouteParamMetadata[];
17
+ }
18
+ export interface ControllerMetadata {
19
+ prefix: string;
20
+ middlewares?: unknown[];
21
+ }
22
+ export type Token<T = unknown> = string | symbol | Constructor<T>;
23
+ export type Provider<T = unknown> = Constructor<T> | {
24
+ provide: Token<T>;
25
+ useValue: T;
26
+ } | {
27
+ provide: Token<T>;
28
+ useClass: Constructor<T>;
29
+ } | {
30
+ provide: Token<T>;
31
+ useFactory: (...args: unknown[]) => T | Promise<T>;
32
+ inject?: Token[];
33
+ };
34
+ export interface DynamicModule {
35
+ module: Constructor;
36
+ providers?: Provider[];
37
+ imports?: Array<Constructor | DynamicModule>;
38
+ exports?: Token[];
39
+ global?: boolean;
40
+ }
41
+ export interface ModuleMetadata {
42
+ controllers?: Constructor[];
43
+ providers?: Provider[];
44
+ imports?: Array<Constructor | DynamicModule>;
45
+ exports?: Token[];
46
+ global?: boolean;
47
+ }
48
+ export interface IMetadataStorage {
49
+ addRoute(target: object, methodName: string, meta: RouteMetadata): void;
50
+ addContract(target: object, methodName: string, contract: ContractSpec): void;
51
+ addMiddleware(target: object, middleware: unknown, methodName?: string): void;
52
+ getRoutes(target: object): Map<string, RouteMetadata> | undefined;
53
+ setController(target: object, meta: ControllerMetadata): void;
54
+ getController(target: object): ControllerMetadata | undefined;
55
+ defineModule(target: object, meta: ModuleMetadata): void;
56
+ getModule(target: object): ModuleMetadata | undefined;
57
+ addInjection(target: object, index: number, token: Token<unknown>): void;
58
+ getInjections(target: object): Map<number, Token<unknown>> | undefined;
59
+ addRouteParam(target: object, methodName: string, param: RouteParamMetadata): void;
60
+ }
61
+ declare global {
62
+ var KANJI_METADATA_STORAGE: IMetadataStorage | undefined;
63
+ }
64
+ export declare const MetadataStorage: IMetadataStorage;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};