@xeno-js/core 2.0.2 → 3.0.0

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/index.d.ts CHANGED
@@ -1,8 +1,21 @@
1
- import { Optional, RequestContext, HttpMethod, AuthConfig, CookieOptions, IServiceExtractor, IExtendendAuthService, SetupAction, HttpClientConfig, LogLevel, ILoggerClient, Dictionary, AuthPolicy, IStrategy, IRequest, ResponseDto, IContextAccessor, ResultType, Identity, ISpecification, IConfigurationService, CacheConfig, DbConfig, ExtendedRequest, IReadDao, IReadDataSource, IMapper, UserContext, IRepository, IWriteDataSource, IController, IMediator, AppError, IQuery, ICommand } from '@xeno-js/shared';
1
+ import { ICache, Optional, IExtendendAuthService, IBaseAuthService, ICacheKeyBuilder, IPipelineBehavior, ICommand, IConcurrencyService, IConfigurationService, ILogger, IMediator, IMiddleware, IQuery, RequestContext, IServiceResilience, IServiceExtractor, Metadata, IUnitOfWork, IDisposable, IValidatorService, IIdentityAccessor, IContextAccessor, INetworkContextAccessor, IFactory, UserContext, ITransactionState, Factory, IBaseAccessor, Identity, ExtendedRequest, HttpMethod, AuthConfig, CookieOptions, SetupAction, HttpClientConfig, LogLevel, ILoggerClient, Dictionary, AuthPolicy, IStrategy, IRequest, ResponseDto, ResultType, ISpecification, CacheConfig, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, AppError } from '@xeno-js/shared';
2
2
  export * from '@xeno-js/shared';
3
3
  export { Query } from '@xeno-js/shared';
4
- import { A as ApplicationRegistry, I as IServiceProvider, a as IServiceScope, b as IServiceContainer, c as IHttpAdapter, X as XenoWebTransport } from './itoken-service.contracts-3GrRvKeZ.js';
5
- export { d as IAtomicCache, e as ICryptoService, f as ICsrfTokenService, g as IRequestContext, h as IServiceScopeAccessor } from './itoken-service.contracts-3GrRvKeZ.js';
4
+
5
+ /**
6
+ * @description IAtomicCache is an interface that extends the ICache interface and adds an increment method. The increment method takes a key and an optional ttlSeconds parameter and returns a Promise that resolves to an incremented value.
7
+ *
8
+ */
9
+ interface IAtomicCache extends ICache {
10
+ /**
11
+ * @description The increment method increments the value associated with the given key in the cache. If the key does not exist, it is created with an initial value of 1. The method returns a Promise that resolves to the incremented value.
12
+ *
13
+ * @param key The key to increment the value for.
14
+ * @param ttlSeconds The time-to-live (TTL) in seconds for the key-value pair. If not provided, the default TTL is used.
15
+ * @returns A Promise that resolves to the incremented value.
16
+ */
17
+ increment(key: string, ttlSeconds: Optional<number | string>): Promise<number>;
18
+ }
6
19
 
7
20
  /**
8
21
  * @description An interface that defines the contract for a rate limit key builder in a Xeno Vue application. This interface requires the implementation of a single method, buildRateLimitKey, which takes a resource and a client IP address as parameters and returns a string representing the rate limit key.
@@ -23,6 +36,380 @@ interface IRateLimitKeyBuilder {
23
36
  buildRateLimitKey(resource: string): Optional<string>;
24
37
  }
25
38
 
39
+ /**
40
+ * @description This file defines the injection tokens used for dependency injection in the application.
41
+ * Injection tokens are unique identifiers that are used to register and resolve dependencies in the container.
42
+ * They can be symbols, strings, or classes, but using symbols is a common practice to avoid naming collisions.
43
+ *
44
+ * @author Xeno
45
+ * @version 1.0.0
46
+ * @since 2025-09-30
47
+ * @link https://github.com/xeno-js/xeno-js
48
+ */
49
+ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
50
+ /** @description Token used to register and resolve the Extended AuthService instance in the dependency injection container.
51
+ *
52
+ * @author Xeno
53
+ * @version 1.0.0
54
+ * @since 2025-09-30
55
+ * @link https://github.com/xeno-js/xeno-js
56
+ */
57
+ readonly AUTH_SERVICE: IExtendendAuthService;
58
+ /** @description Token used to register and resolve the BaseAuthService instance in the dependency injection container.
59
+ *
60
+ * @author Xeno
61
+ * @version 1.0.0
62
+ * @since 2025-09-30
63
+ * @link https://github.com/xeno-js/xeno-js
64
+ */
65
+ readonly BASE_AUTH_SERVICE: IBaseAuthService;
66
+ /** @description Token used to register and resolve the InMemoryCache instance in the dependency injection container.
67
+ *
68
+ * @author Xeno
69
+ * @version 1.0.0
70
+ * @since 2025-09-30
71
+ * @link https://github.com/xeno-js/xeno-js
72
+ */
73
+ readonly CACHE: IAtomicCache;
74
+ /** @description Token used to register and resolve the CacheKeyBuilder instance in the dependency injection container.
75
+ *
76
+ * @author Xeno
77
+ * @version 1.0.0
78
+ * @since 2025-09-30
79
+ * @link https://github.com/xeno-js/xeno-js
80
+ */
81
+ readonly CACHE_KEY_BUILDER: ICacheKeyBuilder;
82
+ /** @description Token used to register and resolve the CommandPipeline behaviors in the dependency injection container.
83
+ *
84
+ * @author Xeno
85
+ * @version 1.0.0
86
+ * @since 2025-09-30
87
+ * @link https://github.com/xeno-js/xeno-js
88
+ */
89
+ readonly COMMAND_PIPELINES_BEHAVIOR: IPipelineBehavior<ICommand, unknown>;
90
+ /** @description Token used to register and resolve the ConcurrencyService instance in the dependency injection container.
91
+ *
92
+ * @author Xeno
93
+ * @version 1.0.0
94
+ * @since 2025-09-30
95
+ * @link https://github.com/xeno-js/xeno-js
96
+ */
97
+ readonly CONCURRENCY_SERVICE: IConcurrencyService;
98
+ /** @description Token used to register and resolve the ConfigurationService instance in the dependency injection container.
99
+ *
100
+ * @author Xeno
101
+ * @version 1.0.0
102
+ * @since 2025-09-30
103
+ * @link https://github.com/xeno-js/xeno-js
104
+ */
105
+ readonly CONFIGURATION_SERVICE: IConfigurationService;
106
+ /** @description Token used to register and resolve the CsrfTokenService instance in the dependency injection container.
107
+ *
108
+ * @author Xeno
109
+ * @version 1.0.0
110
+ * @since 2025-09-30
111
+ * @link https://github.com/xeno-js/xeno-js
112
+ */
113
+ readonly CSRF_TOKEN_SERVICE: ICsrfTokenService;
114
+ /** @description Token used to register and resolve the CryptoService instance in the dependency injection container.
115
+ *
116
+ * @author Xeno
117
+ * @version 1.0.0
118
+ * @since 2025-09-30
119
+ * @link https://github.com/xeno-js/xeno-js
120
+ */
121
+ readonly CRYPTO_SERVICE: ICryptoService;
122
+ /** @description Token used to register and resolve the DbContext instance in the dependency injection container.
123
+ *
124
+ * @author Xeno
125
+ * @version 1.0.0
126
+ * @since 2025-09-30
127
+ * @link https://github.com/xeno-js/xeno-js
128
+ */
129
+ readonly DB_CONTEXT: T;
130
+ /** @description Token used to register and resolve the HTTP Adapter instance in the dependency injection container.
131
+ *
132
+ * @author Xeno
133
+ * @version 1.2.1
134
+ * @since 2025-09-30
135
+ * @link https://github.com/xeno-js/xeno-js
136
+ */
137
+ readonly HTTP_ADAPTER: IHttpAdapter<unknown, unknown>;
138
+ /** @description Token used to register and resolve the Logger instance in the dependency injection container.
139
+ *
140
+ * @author Xeno
141
+ * @version 1.0.0
142
+ * @since 2025-09-30
143
+ * @link https://github.com/xeno-js/xeno-js
144
+ */
145
+ readonly LOGGER: ILogger;
146
+ /** @description Token used to register and resolve the Mediator instance in the dependency injection container.
147
+ *
148
+ * @author Xeno
149
+ * @version 1.0.0
150
+ * @since 2025-09-30
151
+ * @link https://github.com/xeno-js/xeno-js
152
+ */
153
+ readonly MEDIATOR: IMediator;
154
+ /** @description Token used to register and resolve the RequestContextMiddleware in the dependency injection container.
155
+ *
156
+ * @author Xeno
157
+ * @version 1.0.0
158
+ * @since 2025-09-30
159
+ * @link https://github.com/xeno-js/xeno-js
160
+ */
161
+ readonly MIDDLEWARE: IMiddleware;
162
+ /** @description Token used to register and resolve the QueryPipeline behaviors in the dependency injection container.
163
+ *
164
+ * @author Xeno
165
+ * @version 1.0.0
166
+ * @since 2025-09-30
167
+ * @link https://github.com/xeno-js/xeno-js
168
+ */
169
+ readonly QUERY_PIPELINES_BEHAVIOR: IPipelineBehavior<IQuery, unknown>;
170
+ /** @description Token used to register and resolve the RequestContext instance in the dependency injection container.
171
+ *
172
+ * @author Xeno
173
+ * @version 1.0.0
174
+ * @since 2025-09-30
175
+ * @link https://github.com/xeno-js/xeno-js
176
+ */
177
+ readonly REQUEST_CONTEXT: IRequestContext<RequestContext, ApplicationRegistry<T>>;
178
+ /** @description Token used to register and resolve the IServiceResilience instance in the dependency injection container.
179
+ *
180
+ * @author Xeno
181
+ * @version 1.0.0
182
+ * @since 2025-09-30
183
+ * @link https://github.com/xeno-js/xeno-js
184
+ */
185
+ readonly RESILIENCE_CLIENT: IServiceResilience;
186
+ /** @description Token used to register and resolve the ServiceContainer instance in the dependency injection container.
187
+ *
188
+ * @author Xeno
189
+ * @version 1.0.0
190
+ * @since 2025-09-30
191
+ * @link https://github.com/xeno-js/xeno-js
192
+ */
193
+ readonly SERVICE_CONTAINER: IServiceContainer;
194
+ /** @description Token used to register and resolve the ServiceExtractor instance in the dependency injection container.
195
+ *
196
+ * @author Xeno
197
+ * @version 1.0.0
198
+ * @since 2025-09-30
199
+ * @link https://github.com/xeno-js/xeno-js
200
+ */
201
+ readonly SERVICE_EXTRACTOR: IServiceExtractor<Request['headers'], Metadata>;
202
+ /** @description Token used to register and resolve the UnitOfWork instance in the dependency injection container.
203
+ *
204
+ * @author Xeno
205
+ * @version 1.0.0
206
+ * @since 2025-09-30
207
+ * @link https://github.com/xeno-js/xeno-js
208
+ */
209
+ readonly UNIT_OF_WORK: IUnitOfWork & IDisposable;
210
+ /** @description Token used to register and resolve the ZodValidator instance in the dependency injection container.
211
+ *
212
+ * @author Xeno
213
+ * @version 1.0.0
214
+ * @since 2025-09-30
215
+ * @link https://github.com/xeno-js/xeno-js
216
+ */
217
+ readonly VALIDATOR_SERVICE: IValidatorService;
218
+ /** @description Token used to register and resolve the IIdentityAccessor in the dependency injection container, allowing access only to current user identity information.
219
+ *
220
+ * @author Xeno
221
+ * @version 1.0.0
222
+ * @since 2025-09-30
223
+ * @link https://github.com/xeno-js/xeno-js
224
+ */
225
+ readonly IDENTITY_ACCESSOR: IIdentityAccessor;
226
+ /** @description Token used to register and resolve the IServiceScopeAccessor in the dependency injection container, granting controlled access to the current request scope.
227
+ *
228
+ * @author Xeno
229
+ * @version 1.0.0
230
+ * @since 2025-09-30
231
+ * @link https://github.com/xeno-js/xeno-js
232
+ */
233
+ readonly SERVICE_SCOPE_ACCESSOR: IServiceScopeAccessor<ApplicationRegistry<T>>;
234
+ /** @description Token used to register and resolve the IContextAccessor instance in the dependency injection container to fetch execution context properties.
235
+ *
236
+ * @author Xeno
237
+ * @version 1.0.0
238
+ * @since 2025-09-30
239
+ * @link https://github.com/xeno-js/xeno-js
240
+ */
241
+ readonly CONTEXT_ACCESSOR: IContextAccessor<RequestContext>;
242
+ /** @description Token used to register and resolve the INetworkContextAccessor instance in the dependency injection container to fetch networking/observability context data.
243
+ *
244
+ * @author Xeno
245
+ * @version 1.0.0
246
+ * @since 2025-09-30
247
+ * @link https://github.com/xeno-js/xeno-js
248
+ */
249
+ readonly NETWORK_CONTEXT_ACCESSOR: INetworkContextAccessor;
250
+ /** @description Token used to register and resolve the UserContext factory in the dependency injection container.
251
+ *
252
+ * @author Xeno
253
+ * @version 1.0.0
254
+ * @since 2025-09-30
255
+ * @link https://github.com/xeno-js/xeno-js
256
+ */
257
+ readonly USER_CONTEXT_FACTORY: IFactory<void, UserContext>;
258
+ /** @description Token used to register and resolve the TransactionState instance in the dependency injection container.
259
+ *
260
+ * @author Xeno
261
+ * @version 1.0.0
262
+ * @since 2025-09-30
263
+ * @link https://github.com/xeno-js/xeno-js
264
+ */
265
+ readonly TRANSACTION_STATE: ITransactionState<Ttx>;
266
+ }
267
+
268
+ /**
269
+ * @fileoverview Defines the IServiceScope interface for scoped dependency injection.
270
+ *
271
+ * @author Xeno
272
+ * @version 1.0.0
273
+ * @since 2025-09-30
274
+ * @link https://github.com/xeno-js/xeno-js
275
+ */
276
+ /**
277
+ * @description Represents a logical scope for resolving scoped services,
278
+ * mimicking the .NET `IServiceScope` pattern.
279
+ *
280
+ * A scope is created by {@link IServiceContainer.createScope} and provides
281
+ * its own isolated instance cache for services registered with scoped lifetime.
282
+ * Singleton and transient services are still resolved through the root container.
283
+ *
284
+ * Call {@link dispose} when the scope is no longer needed to release all
285
+ * scoped instances and invalidate the scope.
286
+ *
287
+ * @author Xeno
288
+ * @version 1.0.0
289
+ * @since 2025-09-30
290
+ * @link https://github.com/xeno-js/xeno-js
291
+ */
292
+ interface IServiceScope<Registry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> extends IDisposable {
293
+ /**
294
+ * Resolves and returns the service registered under the given token.
295
+ * Scoped services can only be resolved through a scope;
296
+ * resolving them directly from the root container throws an error.
297
+ *
298
+ * @param token - The injection token identifying the service to resolve.
299
+ * @returns The resolved service instance of type `T`.
300
+ * @throws An error if no registration is found for the given token.
301
+ * @throws An error if the scope has already been disposed.
302
+ *
303
+ * @author Xeno
304
+ * @version 1.0.0
305
+ * @since 2025-09-30
306
+ * @link https://github.com/xeno-js/xeno-js
307
+ */
308
+ resolve<K extends keyof Registry>(token: K): Registry[K];
309
+ }
310
+
311
+ /**
312
+ * @fileoverview Defines the IServiceContainer interface for a dependency injection container.
313
+ *
314
+ * @author Xeno
315
+ * @version 1.0.0
316
+ * @since 2025-09-30
317
+ * @link https://github.com/xeno-js/xeno-js
318
+ */
319
+ interface IServiceProvider<Registry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> {
320
+ /**
321
+ * Resolves and returns the service registered under the given token.
322
+ * Scoped services can only be resolved through a scope;
323
+ * resolving them directly from the root container throws an error.
324
+ *
325
+ * @param token - The injection token identifying the service to resolve.
326
+ * @returns The resolved service instance of type `T`.
327
+ * @throws An error if no registration is found for the given token.
328
+ * @throws An error if the scope has already been disposed.
329
+ *
330
+ * @author Xeno
331
+ * @version 1.0.0
332
+ * @since 2025-09-30
333
+ * @link https://github.com/xeno-js/xeno-js
334
+ */
335
+ resolve<K extends keyof Registry>(token: K): Registry[K];
336
+ }
337
+ /**
338
+ * @description Agnostic contract for a dependency injection container that mimics
339
+ * the .NET ServiceCollection builder pattern.
340
+ *
341
+ * Each registration method returns `this` to enable a fluent builder chain.
342
+ * Dependencies are expressed as an ordered array of injection tokens
343
+ * that the container will resolve and inject into the constructor.
344
+ *
345
+ * @author Xeno
346
+ * @version 1.0.0
347
+ * @since 2025-09-30
348
+ * @link https://github.com/xeno-js/xeno-js
349
+ */
350
+ interface IServiceContainer<Registry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> extends IServiceProvider<Registry>, IDisposable {
351
+ /**
352
+ * Registers an implementation under the given token with **singleton** lifetime.
353
+ * A single instance is created on first resolution and reused for every
354
+ * subsequent call within the container's lifetime.
355
+ *
356
+ * @param token - The unique injection token that identifies this service binding.
357
+ * @param factory - Factory function that creates the service instance, receiving the scope as an argument.
358
+ * @returns The container instance to allow method chaining.
359
+ *
360
+ * @author Xeno
361
+ * @version 1.0.0
362
+ * @since 2025-09-30
363
+ * @link https://github.com/xeno-js/xeno-js
364
+ */
365
+ addSingleton<K extends keyof Registry>(token: K, factory: Factory<Registry[K], [IServiceScope<Registry>]>): this;
366
+ /**
367
+ * Registers an implementation under the given token with **transient** lifetime.
368
+ * A new instance is created on every call to {@link resolve}.
369
+ *
370
+ * @param token - The unique injection token that identifies this service binding.
371
+ * @param factory - Factory function that creates the service instance, receiving the scope as an argument.
372
+ * @returns The container instance to allow method chaining.
373
+ *
374
+ * @author Xeno
375
+ * @version 1.0.0
376
+ * @since 2025-09-30
377
+ * @link https://github.com/xeno-js/xeno-js
378
+ */
379
+ addTransient<K extends keyof Registry>(token: K, factory: Factory<Registry[K], [IServiceScope<Registry>]>): this;
380
+ /**
381
+ * Registers an implementation under the given token with **scoped** lifetime.
382
+ * One instance is created per logical scope (e.g. per HTTP request).
383
+ * Scoped services must be resolved through an {@link IServiceScope} obtained
384
+ * via {@link createScope}; resolving them directly from the root container throws.
385
+ *
386
+ * @param token - The unique injection token that identifies this service binding.
387
+ * @param factory - Factory function that creates the service instance, receiving the scope as an argument.
388
+ * @returns The container instance to allow method chaining.
389
+ *
390
+ * @author Xeno
391
+ * @version 1.0.0
392
+ * @since 2025-09-30
393
+ * @link https://github.com/xeno-js/xeno-js
394
+ */
395
+ addScoped<K extends keyof Registry>(token: K, factory: Factory<Registry[K], [IServiceScope<Registry>]>): this;
396
+ /**
397
+ * Creates a new {@link IServiceScope}.
398
+ *
399
+ * The returned scope shares singleton instances with the root container
400
+ * and maintains its own isolated cache for scoped services.
401
+ * Call {@link IServiceScope.dispose} when the scope is no longer needed.
402
+ *
403
+ * @returns A new scope instance.
404
+ *
405
+ * @author Xeno
406
+ * @version 1.0.0
407
+ * @since 2025-09-30
408
+ * @link https://github.com/xeno-js/xeno-js
409
+ */
410
+ createScope(): IServiceScope<Registry>;
411
+ }
412
+
26
413
  /**
27
414
  * @fileoverview Defines the ServiceDescriptor type for service registrations.
28
415
 
@@ -125,6 +512,122 @@ interface ExecutionContext<TRegistry extends ApplicationRegistry = ApplicationRe
125
512
  scope: IServiceScope<TRegistry>;
126
513
  }
127
514
 
515
+ /**
516
+ * @fileoverview Defines the IRequestContext interface for managing user identity context within the application.
517
+ *
518
+ * @author Xeno
519
+ * @version 1.0.0
520
+ * @since 2025-09-30
521
+ * @link https://github.com/xeno-js/xeno-js
522
+ */
523
+
524
+ /**
525
+ * An interface for managing user identity context within the application. This interface provides methods for executing asynchronous functions with the current user's identity context and retrieving the current user's identity information. It allows for seamless integration of identity management into various parts of the application, ensuring that identity-related data is properly propagated and accessible when needed.
526
+ *
527
+ * @author Xeno
528
+ * @version 1.0.0
529
+ * @since 2025-09-30
530
+ * @link https://github.com/xeno-js/xeno-js
531
+ */
532
+ interface IRequestContext<TCtx, TRegistry extends ApplicationRegistry = ApplicationRegistry> extends IBaseAccessor<TCtx>, IServiceScopeAccessor<TRegistry> {
533
+ /**
534
+ * Executes the provided asynchronous function with the current user's identity context. This allows the function to access identity information such as user ID, roles, and correlation ID while performing its operations. The function will be executed within the scope of the current request's identity, ensuring that any identity-related data is properly propagated throughout the execution flow.
535
+ * @param ctx The current user's identity context.
536
+ * @param fn An asynchronous function that takes the current user's identity as an argument and returns a promise of type T. This function will be executed with the identity context of the current request.
537
+ * @returns A promise that resolves to the result of the provided function, allowing the caller to handle the outcome of the operation performed within the identity context.
538
+ *
539
+ * @author Xeno
540
+ * @version 1.0.0
541
+ * @since 2025-09-30
542
+ * @link https://github.com/xeno-js/xeno-js
543
+ */
544
+ runAsync<T = unknown>(ctx: TCtx, fn: () => Promise<T>): Promise<T>;
545
+ updateIdentity(identity: Identity): void;
546
+ }
547
+ /**
548
+ * @description The IIdentityAccessor interface is a contract that defines the structure and behavior of an identity accessor within the application. It provides a method for retrieving the current user's identity information, including user ID, roles, and correlation ID. This interface is essential for managing user identity and ensuring that identity-related data is accessible when needed.
549
+ *
550
+ *
551
+ * @author Xeno
552
+ * @version 1.0.0
553
+ * @since 2025-09-30
554
+ * @link https://github.com/xeno-js/xeno-js
555
+ */
556
+ interface IServiceScopeAccessor<TRegistry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> {
557
+ /**
558
+ * Retrieves the current service scope, which allows for managing dependencies during the execution of a request. This method enables access to the service scope, ensuring that services are properly scoped and disposed of after the request is processed.
559
+ * @returns An object representing the current service scope, allowing for resolution of dependencies and management of services during the execution of a request.
560
+ *
561
+ * @author Xeno
562
+ * @version 1.0.0
563
+ * @since 2025-09-30
564
+ * @link https://github.com/xeno-js/xeno-js
565
+ */
566
+ getScope(): Optional<IServiceScope<TRegistry>>;
567
+ }
568
+
569
+ /**
570
+ * @description Interface for the crypto service
571
+ */
572
+ interface ICryptoService {
573
+ /**
574
+ * @description Generates a random byte array of the specified size.
575
+ * @param size The size of the byte array to generate.
576
+ * @returns A random byte array of the specified size.
577
+ */
578
+ randomBytes(size: number): Uint8Array;
579
+ /**
580
+ * @description Generates a HMAC SHA-256 hash of the specified data using the specified secret.
581
+ * @param secret The secret to use for the HMAC SHA-256 hash.
582
+ * @param data The data to hash.
583
+ * @returns A promise that resolves to the HMAC SHA-256 hash of the specified data.
584
+ */
585
+ hmacSha256(secret: string, data: string): Promise<string>;
586
+ /**
587
+ * @description Compares two byte arrays in a way that is resistant to timing attacks.
588
+ * @param a The first byte array to compare.
589
+ * @param b The second byte array to compare.
590
+ * @returns True if the two byte arrays are equal, false otherwise.
591
+ */
592
+ timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
593
+ }
594
+
595
+ /**
596
+ * @description Interface for a WebTransport.
597
+ * @author Xeno
598
+ * @version 1.2.1
599
+ * @since 2025-09-30
600
+ * @link https://github.com/xeno-js/xeno-js
601
+ */
602
+ interface XenoWebTransport {
603
+ /**
604
+ * @description The Extendend native request.
605
+ * @type ExtendedRequest
606
+ */
607
+ request: ExtendedRequest;
608
+ /**
609
+ * @description The native response.
610
+ * @type Response
611
+ */
612
+ response: Response;
613
+ }
614
+ /**
615
+ * @description Interface for an HTTP adapter.
616
+ * @author Xeno
617
+ * @version 1.2.1
618
+ * @since 2025-09-30
619
+ * @link https://github.com/xeno-js/xeno-js
620
+ */
621
+ interface IHttpAdapter<TReq = Request, TRes = Response> {
622
+ /**
623
+ * @description Adapts an HTTP request and response to an ExtendedRequest and Response.
624
+ * @param req - The HTTP request.
625
+ * @param res - The HTTP response.
626
+ * @returns An object containing the adapted ExtendedRequest and Response.
627
+ */
628
+ adapt(req: TReq, res: TRes): XenoWebTransport;
629
+ }
630
+
128
631
  /**
129
632
  * @description Represents a module that can be registered with the service container.
130
633
  *
@@ -218,6 +721,29 @@ interface IAllowOrigin {
218
721
  isAllowed(origin: Optional<string>): boolean;
219
722
  }
220
723
 
724
+ /**
725
+ * @description Interface for the CSRF token service
726
+ */
727
+ interface ICsrfTokenService {
728
+ /**
729
+ * @description Generate a new CSRF token
730
+ * @param subject The subject of the token
731
+ * @returns A promise that resolves to the token
732
+ */
733
+ generate(subject: string): Promise<string>;
734
+ /**
735
+ * @description Validate a CSRF token
736
+ * @param token The token to validate
737
+ * @param subject The subject of the token
738
+ * @returns A priomise that resolves to true if the token is valid, false otherwise
739
+ */
740
+ validate(token: string, subject: string): Promise<boolean>;
741
+ }
742
+
743
+ interface ITransactionalDb<TTransaction = unknown> {
744
+ transaction<T>(callback: (tx: TTransaction) => Promise<T>): Promise<T>;
745
+ }
746
+
221
747
  interface ISsrCookie {
222
748
  name: string;
223
749
  value: string;
@@ -241,6 +767,18 @@ interface AuthSsrConfig<TOption = unknown, TRegistry extends ApplicationRegistry
241
767
  }>;
242
768
  }
243
769
 
770
+ /**
771
+ * @description Options for configuring the database module.
772
+ * @author Xeno
773
+ * @version 1.0.0
774
+ * @since 2025-09-30
775
+ * @link https://github.com/xeno-js/xeno-js
776
+ */
777
+ interface DbModuleOptions<TDb extends ITransactionalDb<Ttx>, Ttx = unknown> {
778
+ /** The database client to use. */
779
+ readonly client: TDb;
780
+ }
781
+
244
782
  /**
245
783
  * @description This file defines the ResilienceConfig interface, which specifies the configuration options for implementing resilience features such as retries, circuit breakers, and bulkheads in service calls. The ResilienceConfig interface includes properties for configuring retry attempts, base delay, maximum delay, consecutive failures for circuit breakers, half-open timeout, and maximum concurrent operations for bulkheads. This configuration can be used to enhance the reliability of service interactions by automatically handling transient faults and preventing cascading failures in distributed systems.
246
784
 
@@ -1094,6 +1632,20 @@ declare abstract class Specification<T> implements ISpecification<T> {
1094
1632
  not(): ISpecification<T>;
1095
1633
  }
1096
1634
 
1635
+ /**
1636
+ * @description The AppBuilder class provides a fluent, .NET-style API for configuring and bootstrapping the application. It orchestrates the registration of various modules (CQRS, HTTP, Database, Logging, Auth) into the ServiceContainer.
1637
+
1638
+ *
1639
+ * @author Xeno
1640
+ * @version 1.0.0
1641
+ * @since 2025-09-30
1642
+ * @link https://github.com/xeno-js/xeno-js
1643
+ */
1644
+ interface QueuedModule {
1645
+ priority: number;
1646
+ name: string;
1647
+ action: () => Promise<void>;
1648
+ }
1097
1649
  /**
1098
1650
  * @description The AppBuilder class provides a fluent, .NET-style API for configuring and bootstrapping the application.
1099
1651
  * It orchestrates the registration of various modules (CQRS, HTTP, Database, Logging, Auth) into the ServiceContainer.
@@ -1105,11 +1657,11 @@ declare abstract class Specification<T> implements ISpecification<T> {
1105
1657
  * @link https://github.com/xeno-js/xeno-js
1106
1658
  */
1107
1659
  declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegistry> {
1108
- private readonly _container;
1109
- private readonly _configuration;
1660
+ protected readonly _container: IServiceContainer<TRegistry>;
1661
+ protected readonly _configuration: IConfigurationService;
1110
1662
  private _isBuilded;
1111
1663
  constructor(container?: IServiceContainer<TRegistry>, configurationService?: IConfigurationService);
1112
- private readonly _modules;
1664
+ protected readonly _modules: QueuedModule[];
1113
1665
  private _adapterConfig;
1114
1666
  private _pipelineConfig;
1115
1667
  private _config;
@@ -1126,7 +1678,7 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1126
1678
  private _isConcurrencyServiceQueued;
1127
1679
  private _isCacheModuleQueued;
1128
1680
  private _isAdapterModuleQueued;
1129
- addAdapter(setupAction: SetupAction<HttpAdapterConfig, IConfigurationService>): this;
1681
+ protected addAdapter(setupAction: SetupAction<HttpAdapterConfig, IConfigurationService>): this;
1130
1682
  /**
1131
1683
  * @description Enables the use of middlewares in the application. Middlewares can be used for cross-cutting concerns such as logging, authentication, and request/response manipulation.
1132
1684
  * @returns The current instance of AppBuilder for method chaining.
@@ -1195,7 +1747,7 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1195
1747
  * @since 2025-09-30
1196
1748
  * @link https://github.com/xeno-js/xeno-js
1197
1749
  */
1198
- addDb(setupAction: SetupAction<DbConfig, IConfigurationService>): this;
1750
+ addDb(plugin: (builder: this) => this): this;
1199
1751
  /**
1200
1752
  * @description Enables the use of the service for concurrency control in the application. This method allows you to limit the number of concurrent asynchronous tasks being executed, which is useful for managing system resources and preventing event loop blocking during massive batch operations.
1201
1753
  * @returns The current instance of AppBuilder for method chaining.
@@ -1357,6 +1909,18 @@ declare abstract class BaseHttpAdapter<TReq = ExtendedRequest, TRes = Response>
1357
1909
  protected createXenoWebTransport(url: URL, method: string | undefined, headers: Headers, body?: Optional<unknown>, res?: Optional<TRes>): XenoWebTransport;
1358
1910
  }
1359
1911
 
1912
+ /**
1913
+ * @description The DbModule class is responsible for configuring the database module within the application. It implements the IModule interface, allowing it to be integrated into the application's dependency injection system. The configure method registers a singleton factory for creating an IDbClient instance using the provided configuration options. This design promotes modularity and allows for easy management of database connections and operations throughout the application.
1914
+ *
1915
+ * @author Xeno
1916
+ * @version 1.0.0
1917
+ * @since 2025-09-30
1918
+ * @link https://github.com/xeno-js/xeno-js
1919
+ */
1920
+ declare class DbModule<TRegistry extends ApplicationRegistry<DbContext, DbTransaction>, DbContext extends ITransactionalDb<DbTransaction>, DbTransaction = unknown> implements IModule<TRegistry, DbModuleOptions<DbContext, DbTransaction>> {
1921
+ configure(container: IServiceContainer<TRegistry>, opts: DbModuleOptions<DbContext, DbTransaction>): Promise<void>;
1922
+ }
1923
+
1360
1924
  /**
1361
1925
  * An abstract generic read-only DAO that provides basic read operations for entities of type T, using a Data Transfer Object (DTO) of type TDto for data access. This class relies on an IReadDataSource to perform database operations and an IMapper to convert between entities and DTOs.
1362
1926
  * @template T - The type of the entity that the DAO will manage.
@@ -1509,4 +2073,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
1509
2073
  protected getContext(): Optional<RequestContext>;
1510
2074
  }
1511
2075
 
1512
- export { AppBuilder, ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHttpAdapter, ContainerUtils, type CookieHandlerOptions, type ExecutionContext, type HttpAdapterConfig, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, IHttpAdapter, type IIPResolver, type IModule, type IRateLimitKeyBuilder, IServiceContainer, IServiceProvider, IServiceScope, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, type XenoRegistry, XenoWebTransport };
2076
+ export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHttpAdapter, ContainerUtils, type CookieHandlerOptions, DbModule, type DbModuleOptions, type ExecutionContext, type HttpAdapterConfig, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, type IAtomicCache, type ICryptoService, type ICsrfTokenService, type IHttpAdapter, type IIPResolver, type IModule, type IRateLimitKeyBuilder, type IRequestContext, type IServiceContainer, type IServiceProvider, type IServiceScope, type IServiceScopeAccessor, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type ITransactionalDb, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, type XenoRegistry, type XenoWebTransport };