truxie 0.1.0-test.6 → 0.1.0-test.7

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/cqrs.d.ts ADDED
@@ -0,0 +1,164 @@
1
+ import { D as DynamicModule, a as Type } from './types-D-An5cXP.js';
2
+
3
+ /**
4
+ * Enables CQRS with CommandBus, QueryBus, and auto-discovered handlers.
5
+ *
6
+ * Import with `CqrsModule.forRoot()` in your root module.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * @Module({
11
+ * imports: [CqrsModule.forRoot()],
12
+ * })
13
+ * export class AppModule {}
14
+ *
15
+ * // Define a command:
16
+ * class CreateUserCommand {
17
+ * constructor(public readonly email: string, public readonly name: string) {}
18
+ * }
19
+ *
20
+ * // Register handler in a module's providers:
21
+ * @CommandHandler(CreateUserCommand)
22
+ * @Injectable()
23
+ * @Inject(UserService)
24
+ * class CreateUserHandler implements ICommandHandler<CreateUserCommand, IUser> {
25
+ * constructor(private readonly userService: UserService) {}
26
+ * async execute(command: CreateUserCommand) {
27
+ * return this.userService.create(command)
28
+ * }
29
+ * }
30
+ *
31
+ * // Dispatch from controller:
32
+ * @Injectable()
33
+ * @Inject(CommandBus)
34
+ * class AuthController {
35
+ * constructor(private readonly commandBus: CommandBus) {}
36
+ *
37
+ * @Post('/register')
38
+ * async register(@Body() body: RegisterInput) {
39
+ * return this.commandBus.execute(new CreateUserCommand(body.email, body.name))
40
+ * }
41
+ * }
42
+ * ```
43
+ */
44
+ declare class CqrsModule {
45
+ static forRoot(): DynamicModule;
46
+ }
47
+
48
+ /** Marker interface for commands. */
49
+ interface ICommand {
50
+ }
51
+ /** Marker interface for queries. */
52
+ interface IQuery {
53
+ }
54
+ /** Handler that executes a command. */
55
+ interface ICommandHandler<TCommand extends ICommand = ICommand, TResult = void> {
56
+ execute(command: TCommand): Promise<TResult>;
57
+ }
58
+ /** Handler that executes a query. */
59
+ interface IQueryHandler<TQuery extends IQuery = IQuery, TResult = unknown> {
60
+ execute(query: TQuery): Promise<TResult>;
61
+ }
62
+
63
+ /**
64
+ * Dispatches commands to their registered handlers.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * @Injectable()
69
+ * @Inject(CommandBus)
70
+ * class AuthController {
71
+ * constructor(private readonly commandBus: CommandBus) {}
72
+ *
73
+ * @Post('/register')
74
+ * async register(@Body() body: RegisterInput) {
75
+ * return this.commandBus.execute(new CreateUserCommand(body.email, body.name))
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ declare class CommandBus {
81
+ private handlers;
82
+ /** @internal — called by CqrsExplorer during bootstrap. */
83
+ register(commandClass: Type, handler: ICommandHandler): void;
84
+ /**
85
+ * Execute a command by dispatching it to the registered handler.
86
+ * Throws if no handler is registered for the command type.
87
+ */
88
+ execute<TResult = void>(command: ICommand): Promise<TResult>;
89
+ }
90
+
91
+ /**
92
+ * Dispatches queries to their registered handlers.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * @Injectable()
97
+ * @Inject(QueryBus)
98
+ * class UserController {
99
+ * constructor(private readonly queryBus: QueryBus) {}
100
+ *
101
+ * @Get('/:id')
102
+ * async getUser(@Param('id') id: string) {
103
+ * return this.queryBus.execute(new GetUserQuery(id))
104
+ * }
105
+ * }
106
+ * ```
107
+ */
108
+ declare class QueryBus {
109
+ private handlers;
110
+ /** @internal — called by CqrsExplorer during bootstrap. */
111
+ register(queryClass: Type, handler: IQueryHandler): void;
112
+ /**
113
+ * Execute a query by dispatching it to the registered handler.
114
+ * Throws if no handler is registered for the query type.
115
+ */
116
+ execute<TResult = unknown>(query: IQuery): Promise<TResult>;
117
+ }
118
+
119
+ /**
120
+ * Marks a class as a command handler for a specific command type.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * class CreateUserCommand {
125
+ * constructor(public readonly email: string, public readonly name: string) {}
126
+ * }
127
+ *
128
+ * @CommandHandler(CreateUserCommand)
129
+ * @Injectable()
130
+ * @Inject(UserService)
131
+ * class CreateUserHandler implements ICommandHandler<CreateUserCommand, IUser> {
132
+ * constructor(private readonly userService: UserService) {}
133
+ *
134
+ * async execute(command: CreateUserCommand): Promise<IUser> {
135
+ * return this.userService.create(command)
136
+ * }
137
+ * }
138
+ * ```
139
+ */
140
+ declare function CommandHandler(command: Type): ClassDecorator;
141
+ /**
142
+ * Marks a class as a query handler for a specific query type.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * class GetUserQuery {
147
+ * constructor(public readonly id: string) {}
148
+ * }
149
+ *
150
+ * @QueryHandler(GetUserQuery)
151
+ * @Injectable()
152
+ * @Inject(UserService)
153
+ * class GetUserHandler implements IQueryHandler<GetUserQuery, IUser> {
154
+ * constructor(private readonly userService: UserService) {}
155
+ *
156
+ * async execute(query: GetUserQuery): Promise<IUser> {
157
+ * return this.userService.findById(query.id)
158
+ * }
159
+ * }
160
+ * ```
161
+ */
162
+ declare function QueryHandler(query: Type): ClassDecorator;
163
+
164
+ export { CommandBus, CommandHandler, CqrsModule, type ICommand, type ICommandHandler, type IQuery, type IQueryHandler, QueryBus, QueryHandler };
package/dist/cqrs.js ADDED
@@ -0,0 +1 @@
1
+ import {a as a$1}from'./chunk-NXAGO5NO.js';import {b as b$1,a as a$2}from'./chunk-XZNMJJJU.js';import {c,d as d$1}from'./chunk-N277L4OB.js';import {a}from'./chunk-EI7MMDWY.js';import'reflect-metadata';function w(n,e,t,o){var c=arguments.length,r=c<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,e,t,o);else for(var f=n.length-1;f>=0;f--)(a=n[f])&&(r=(c<3?a(r):c>3?a(e,t,r):a(e,t))||r);return c>3&&r&&Object.defineProperty(e,t,r),r}a(w,"_ts_decorate");var l=class{static{a(this,"CommandBus");}handlers=new Map;register(e,t){if(this.handlers.has(e))throw new Error(`Duplicate command handler for ${e.name}. Each command must have exactly one handler.`);this.handlers.set(e,t);}async execute(e){let t=e.constructor,o=this.handlers.get(t);if(!o)throw new Error(`No handler registered for command ${t.name}`);return o.execute(e)}};l=w([c()],l);function g(n,e,t,o){var c=arguments.length,r=c<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,e,t,o);else for(var f=n.length-1;f>=0;f--)(a=n[f])&&(r=(c<3?a(r):c>3?a(e,t,r):a(e,t))||r);return c>3&&r&&Object.defineProperty(e,t,r),r}a(g,"_ts_decorate");var s=class{static{a(this,"QueryBus");}handlers=new Map;register(e,t){if(this.handlers.has(e))throw new Error(`Duplicate query handler for ${e.name}. Each query must have exactly one handler.`);this.handlers.set(e,t);}async execute(e){let t=e.constructor,o=this.handlers.get(t);if(!o)throw new Error(`No handler registered for query ${t.name}`);return o.execute(e)}};s=g([c()],s);var b=Symbol("cqrs:command-handler"),R=Symbol("cqrs:query-handler");function M(n){return e=>{Reflect.defineMetadata(b,n,e);}}a(M,"CommandHandler");function _(n){return e=>{Reflect.defineMetadata(R,n,e);}}a(_,"QueryHandler");function j(n){return Reflect.getOwnMetadata(b,n)}a(j,"getCommandHandlerMetadata");function x(n){return Reflect.getOwnMetadata(R,n)}a(x,"getQueryHandlerMetadata");function D(n,e,t,o){var c=arguments.length,r=c<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,e,t,o);else for(var f=n.length-1;f>=0;f--)(a=n[f])&&(r=(c<3?a(r):c>3?a(e,t,r):a(e,t))||r);return c>3&&r&&Object.defineProperty(e,t,r),r}a(D,"_ts_decorate");function O(n,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,e)}a(O,"_ts_metadata");var d=class{static{a(this,"CqrsExplorer");}discovery;commandBus;queryBus;constructor(e,t,o){this.discovery=e,this.commandBus=t,this.queryBus=o;}async onApplicationBootstrap(){let e=this.discovery.getProviders();for(let t of e){let o=this.discovery.getProviderClass(t);if(!o)continue;let c=j(o),r=x(o);if(!c&&!r)continue;let a=typeof t=="function"?t:t.provide,f;try{f=await this.discovery.resolve(a);}catch{continue}c&&this.commandBus.register(c,f),r&&this.queryBus.register(r,f);}}};d=D([c(),d$1(a$1,l,s),O("design:type",Function),O("design:paramtypes",[typeof a$1>"u"?Object:a$1,typeof l>"u"?Object:l,typeof s>"u"?Object:s])],d);function B(n,e,t,o){var c=arguments.length,r=c<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,t):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,e,t,o);else for(var f=n.length-1;f>=0;f--)(a=n[f])&&(r=(c<3?a(r):c>3?a(e,t,r):a(e,t))||r);return c>3&&r&&Object.defineProperty(e,t,r),r}a(B,"_ts_decorate");var m=class n{static{a(this,"CqrsModule");}static forRoot(){return {module:n,global:true,providers:[l,s,d],exports:[l,s]}}};m=B([b$1(),a$2({})],m);export{l as CommandBus,M as CommandHandler,m as CqrsModule,s as QueryBus,_ as QueryHandler};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "truxie",
3
- "version": "0.1.0-test.6",
3
+ "version": "0.1.0-test.7",
4
4
  "description": "NestJS-like structural backend library with DI, modules, guards, interceptors, pipes, and exception filters",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -51,6 +51,11 @@
51
51
  "types": "./dist/ws.d.ts",
52
52
  "import": "./dist/ws.js",
53
53
  "default": "./dist/ws.js"
54
+ },
55
+ "./cqrs": {
56
+ "types": "./dist/cqrs.d.ts",
57
+ "import": "./dist/cqrs.js",
58
+ "default": "./dist/cqrs.js"
54
59
  }
55
60
  },
56
61
  "files": [