@xeno-js/core 1.2.6 → 1.2.8
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.cjs +23 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +23 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1324,6 +1324,14 @@ interface PipelineConfig<TRegistry extends ApplicationRegistry<unknown> = Applic
|
|
|
1324
1324
|
* @link https://github.com/xeno-js/xeno-js
|
|
1325
1325
|
*/
|
|
1326
1326
|
thresholdMs: Optional<number>;
|
|
1327
|
+
/** @description Optional threshold in milliseconds for logging slow operations by intent. If defined, the PerformancePipeline will log a warning whenever the execution of a command or query exceeds this duration, allowing for performance monitoring and optimization. If not defined, all operations will be monitored without duration-based filtering.
|
|
1328
|
+
*
|
|
1329
|
+
* @author Xeno
|
|
1330
|
+
* @version 1.0.0
|
|
1331
|
+
* @since 2025-09-30
|
|
1332
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
1333
|
+
*/
|
|
1334
|
+
intentThresholdMs: Optional<Dictionary<number>>;
|
|
1327
1335
|
};
|
|
1328
1336
|
/** @description Configuration for authorization, allowing the enabling of authorization strategies based on tenant, policy, roles, and permissions. If enabled, the authorization pipeline will evaluate the specified strategies for each command or query, ensuring that only authorized users can perform certain actions. The configuration also includes the ability to define custom authorization strategies via injection tokens, providing flexibility in implementing application-specific access rules.
|
|
1329
1337
|
*
|
|
@@ -1950,6 +1958,57 @@ declare class SupabaseServerAuthFactory<TRegistry extends XenoRegistry = XenoReg
|
|
|
1950
1958
|
private _getCookieSsr;
|
|
1951
1959
|
}
|
|
1952
1960
|
|
|
1961
|
+
/**
|
|
1962
|
+
* @description Base HTTP adapter.
|
|
1963
|
+
* @author Xeno
|
|
1964
|
+
* @version 1.2.1
|
|
1965
|
+
* @since 2025-09-30
|
|
1966
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
1967
|
+
*/
|
|
1968
|
+
declare abstract class BaseHttpAdapter<TReq = ExtendedRequest, TRes = Response> implements IHttpAdapter<TReq, TRes> {
|
|
1969
|
+
abstract adapt(req: TReq, res: TRes): XenoWebTransport;
|
|
1970
|
+
/**
|
|
1971
|
+
* @description Parse the URL from the request.
|
|
1972
|
+
* @param rawUrl The raw URL.
|
|
1973
|
+
* @param headers The headers.
|
|
1974
|
+
* @param queryParams The query parameters.
|
|
1975
|
+
* @returns The parsed URL.
|
|
1976
|
+
*/
|
|
1977
|
+
protected parseUrl(rawUrl: string | undefined, headers: Dictionary<Optional<string | string[]>>, queryParams: Optional<Dictionary>): URL;
|
|
1978
|
+
/**
|
|
1979
|
+
* @description Parses the headers.
|
|
1980
|
+
* @param rawHeaders The raw headers.
|
|
1981
|
+
* @returns The parsed headers.
|
|
1982
|
+
*/
|
|
1983
|
+
protected parseHeaders(rawHeaders: Dictionary<Optional<string | string[]>>): Headers;
|
|
1984
|
+
/**
|
|
1985
|
+
* @description Parses the body.
|
|
1986
|
+
* @param method The method.
|
|
1987
|
+
* @param rawBody The raw body.
|
|
1988
|
+
* @returns The parsed body.
|
|
1989
|
+
*/
|
|
1990
|
+
protected parseBody(method: Optional<string>, rawBody: unknown): Optional<RequestInit['body']>;
|
|
1991
|
+
/**
|
|
1992
|
+
* @description Handles the header change.
|
|
1993
|
+
* @param res The response.
|
|
1994
|
+
* @param name The name.
|
|
1995
|
+
* @param value The value.
|
|
1996
|
+
* @param action The action.
|
|
1997
|
+
* @param action The action.
|
|
1998
|
+
* @returns void
|
|
1999
|
+
*/
|
|
2000
|
+
protected abstract handleHeaderChange(_res: TRes, _name: string, _value: string, _action: 'set' | 'append' | 'delete'): void;
|
|
2001
|
+
/**
|
|
2002
|
+
* @description Creates the XenoWebTransport.
|
|
2003
|
+
* @param url The url.
|
|
2004
|
+
* @param method The method.
|
|
2005
|
+
* @param headers The headers.
|
|
2006
|
+
* @param body The body.
|
|
2007
|
+
* @returns The XenoWebTransport.
|
|
2008
|
+
*/
|
|
2009
|
+
protected createXenoWebTransport(url: URL, method: string | undefined, headers: Headers, body?: Optional<unknown>, res?: Optional<TRes>): XenoWebTransport;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
1953
2012
|
/**
|
|
1954
2013
|
* 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.
|
|
1955
2014
|
* @template T - The type of the entity that the DAO will manage.
|
|
@@ -2093,4 +2152,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
|
|
|
2093
2152
|
protected getContext(): Optional<RequestContext>;
|
|
2094
2153
|
}
|
|
2095
2154
|
|
|
2096
|
-
export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, BasePostgresSqlDataSource, BaseSqliteSqlDataSource, ContainerUtils, type CookieHandlerOptions, type DbContext, type DbTransaction, 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 Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry, type XenoWebTransport };
|
|
2155
|
+
export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, BaseHttpAdapter, BasePostgresSqlDataSource, BaseSqliteSqlDataSource, ContainerUtils, type CookieHandlerOptions, type DbContext, type DbTransaction, 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 Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry, type XenoWebTransport };
|
package/dist/index.d.ts
CHANGED
|
@@ -1324,6 +1324,14 @@ interface PipelineConfig<TRegistry extends ApplicationRegistry<unknown> = Applic
|
|
|
1324
1324
|
* @link https://github.com/xeno-js/xeno-js
|
|
1325
1325
|
*/
|
|
1326
1326
|
thresholdMs: Optional<number>;
|
|
1327
|
+
/** @description Optional threshold in milliseconds for logging slow operations by intent. If defined, the PerformancePipeline will log a warning whenever the execution of a command or query exceeds this duration, allowing for performance monitoring and optimization. If not defined, all operations will be monitored without duration-based filtering.
|
|
1328
|
+
*
|
|
1329
|
+
* @author Xeno
|
|
1330
|
+
* @version 1.0.0
|
|
1331
|
+
* @since 2025-09-30
|
|
1332
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
1333
|
+
*/
|
|
1334
|
+
intentThresholdMs: Optional<Dictionary<number>>;
|
|
1327
1335
|
};
|
|
1328
1336
|
/** @description Configuration for authorization, allowing the enabling of authorization strategies based on tenant, policy, roles, and permissions. If enabled, the authorization pipeline will evaluate the specified strategies for each command or query, ensuring that only authorized users can perform certain actions. The configuration also includes the ability to define custom authorization strategies via injection tokens, providing flexibility in implementing application-specific access rules.
|
|
1329
1337
|
*
|
|
@@ -1950,6 +1958,57 @@ declare class SupabaseServerAuthFactory<TRegistry extends XenoRegistry = XenoReg
|
|
|
1950
1958
|
private _getCookieSsr;
|
|
1951
1959
|
}
|
|
1952
1960
|
|
|
1961
|
+
/**
|
|
1962
|
+
* @description Base HTTP adapter.
|
|
1963
|
+
* @author Xeno
|
|
1964
|
+
* @version 1.2.1
|
|
1965
|
+
* @since 2025-09-30
|
|
1966
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
1967
|
+
*/
|
|
1968
|
+
declare abstract class BaseHttpAdapter<TReq = ExtendedRequest, TRes = Response> implements IHttpAdapter<TReq, TRes> {
|
|
1969
|
+
abstract adapt(req: TReq, res: TRes): XenoWebTransport;
|
|
1970
|
+
/**
|
|
1971
|
+
* @description Parse the URL from the request.
|
|
1972
|
+
* @param rawUrl The raw URL.
|
|
1973
|
+
* @param headers The headers.
|
|
1974
|
+
* @param queryParams The query parameters.
|
|
1975
|
+
* @returns The parsed URL.
|
|
1976
|
+
*/
|
|
1977
|
+
protected parseUrl(rawUrl: string | undefined, headers: Dictionary<Optional<string | string[]>>, queryParams: Optional<Dictionary>): URL;
|
|
1978
|
+
/**
|
|
1979
|
+
* @description Parses the headers.
|
|
1980
|
+
* @param rawHeaders The raw headers.
|
|
1981
|
+
* @returns The parsed headers.
|
|
1982
|
+
*/
|
|
1983
|
+
protected parseHeaders(rawHeaders: Dictionary<Optional<string | string[]>>): Headers;
|
|
1984
|
+
/**
|
|
1985
|
+
* @description Parses the body.
|
|
1986
|
+
* @param method The method.
|
|
1987
|
+
* @param rawBody The raw body.
|
|
1988
|
+
* @returns The parsed body.
|
|
1989
|
+
*/
|
|
1990
|
+
protected parseBody(method: Optional<string>, rawBody: unknown): Optional<RequestInit['body']>;
|
|
1991
|
+
/**
|
|
1992
|
+
* @description Handles the header change.
|
|
1993
|
+
* @param res The response.
|
|
1994
|
+
* @param name The name.
|
|
1995
|
+
* @param value The value.
|
|
1996
|
+
* @param action The action.
|
|
1997
|
+
* @param action The action.
|
|
1998
|
+
* @returns void
|
|
1999
|
+
*/
|
|
2000
|
+
protected abstract handleHeaderChange(_res: TRes, _name: string, _value: string, _action: 'set' | 'append' | 'delete'): void;
|
|
2001
|
+
/**
|
|
2002
|
+
* @description Creates the XenoWebTransport.
|
|
2003
|
+
* @param url The url.
|
|
2004
|
+
* @param method The method.
|
|
2005
|
+
* @param headers The headers.
|
|
2006
|
+
* @param body The body.
|
|
2007
|
+
* @returns The XenoWebTransport.
|
|
2008
|
+
*/
|
|
2009
|
+
protected createXenoWebTransport(url: URL, method: string | undefined, headers: Headers, body?: Optional<unknown>, res?: Optional<TRes>): XenoWebTransport;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
1953
2012
|
/**
|
|
1954
2013
|
* 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.
|
|
1955
2014
|
* @template T - The type of the entity that the DAO will manage.
|
|
@@ -2093,4 +2152,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
|
|
|
2093
2152
|
protected getContext(): Optional<RequestContext>;
|
|
2094
2153
|
}
|
|
2095
2154
|
|
|
2096
|
-
export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, BasePostgresSqlDataSource, BaseSqliteSqlDataSource, ContainerUtils, type CookieHandlerOptions, type DbContext, type DbTransaction, 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 Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry, type XenoWebTransport };
|
|
2155
|
+
export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, BaseHttpAdapter, BasePostgresSqlDataSource, BaseSqliteSqlDataSource, ContainerUtils, type CookieHandlerOptions, type DbContext, type DbTransaction, 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 Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry, type XenoWebTransport };
|
package/dist/index.js
CHANGED
|
@@ -583,7 +583,7 @@ var init_performance_pipeline = __esm({
|
|
|
583
583
|
* @since 2025-09-30
|
|
584
584
|
* @link https://github.com/xeno-js/xeno-js
|
|
585
585
|
*/
|
|
586
|
-
constructor(_logger, thresholdMs = defaultThresholdMs) {
|
|
586
|
+
constructor(_logger, intentThresholdMS = {}, thresholdMs = defaultThresholdMs) {
|
|
587
587
|
this._logger = _logger;
|
|
588
588
|
const message = `Invalid thresholdMs value: ${thresholdMs}. It must be a positive integer.`;
|
|
589
589
|
Guards5.throwIfNegative(thresholdMs, message);
|
|
@@ -591,6 +591,15 @@ var init_performance_pipeline = __esm({
|
|
|
591
591
|
throw new Error(message);
|
|
592
592
|
}
|
|
593
593
|
this._thresholdMs = thresholdMs;
|
|
594
|
+
for (const [intent, val] of Object.entries(intentThresholdMS)) {
|
|
595
|
+
const intentMessage = `Invalid thresholdMs value for intent '${intent}': ${val}. It must be a positive integer.`;
|
|
596
|
+
Guards5.throwIfNegative(val, intentMessage);
|
|
597
|
+
Guards5.throwIfNotInteger(val, intentMessage);
|
|
598
|
+
if (val === 0) {
|
|
599
|
+
throw new Error(intentMessage);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
this._intentThresholdMS = intentThresholdMS;
|
|
594
603
|
}
|
|
595
604
|
_logger;
|
|
596
605
|
/**
|
|
@@ -603,6 +612,7 @@ var init_performance_pipeline = __esm({
|
|
|
603
612
|
* @link https://github.com/xeno-js/xeno-js
|
|
604
613
|
*/
|
|
605
614
|
_thresholdMs;
|
|
615
|
+
_intentThresholdMS;
|
|
606
616
|
async handle(request, next) {
|
|
607
617
|
const startTime = performance.now();
|
|
608
618
|
try {
|
|
@@ -610,7 +620,8 @@ var init_performance_pipeline = __esm({
|
|
|
610
620
|
} finally {
|
|
611
621
|
const endTime = performance.now();
|
|
612
622
|
const duration = endTime - startTime;
|
|
613
|
-
|
|
623
|
+
const thresholdMs = this._intentThresholdMS?.[request.intent] ?? this._thresholdMs;
|
|
624
|
+
if (duration > thresholdMs) {
|
|
614
625
|
this._logger.warn(`Performance warning: ${request.intent} took ${duration.toFixed(2)}ms`);
|
|
615
626
|
}
|
|
616
627
|
}
|
|
@@ -2984,7 +2995,7 @@ var init_cqrs_module = __esm({
|
|
|
2984
2995
|
"use strict";
|
|
2985
2996
|
CqrsModule = class {
|
|
2986
2997
|
async configure(container, opts) {
|
|
2987
|
-
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2998
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2988
2999
|
const logger = container.resolve(TOKENS5.LOGGER);
|
|
2989
3000
|
const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2990
3001
|
container.addSingleton(TOKENS5.MEDIATOR, (c) => {
|
|
@@ -2998,9 +3009,8 @@ var init_cqrs_module = __esm({
|
|
|
2998
3009
|
const pipelines = [
|
|
2999
3010
|
new ExceptionPipeline2(),
|
|
3000
3011
|
new LoggingPipeline2(logger),
|
|
3001
|
-
new PerformancePipeline2(logger, thresholdMs)
|
|
3012
|
+
new PerformancePipeline2(logger, opts.performance.intentThresholdMs, thresholdMs)
|
|
3002
3013
|
];
|
|
3003
|
-
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
3004
3014
|
if (Guards51.isDefined(opts.authorization.policies) || Guards51.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
3005
3015
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
3006
3016
|
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
@@ -3335,11 +3345,11 @@ var init_fastify_http_adapter = __esm({
|
|
|
3335
3345
|
"use strict";
|
|
3336
3346
|
init_base_http_adapter();
|
|
3337
3347
|
FastifyHttpAdapter = class extends BaseHttpAdapter {
|
|
3338
|
-
adapt(req,
|
|
3348
|
+
adapt(req, res) {
|
|
3339
3349
|
const headers = this.parseHeaders(req.headers);
|
|
3340
3350
|
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3341
3351
|
const body = req.body;
|
|
3342
|
-
return this.createXenoWebTransport(url, req.method, headers, body);
|
|
3352
|
+
return this.createXenoWebTransport(url, req.method, headers, body, res);
|
|
3343
3353
|
}
|
|
3344
3354
|
handleHeaderChange(res, name, value, action) {
|
|
3345
3355
|
if (action === "delete") {
|
|
@@ -3398,10 +3408,10 @@ var init_vercel_http_adapter = __esm({
|
|
|
3398
3408
|
"use strict";
|
|
3399
3409
|
init_base_http_adapter();
|
|
3400
3410
|
VercelHttpAdapter = class extends BaseHttpAdapter {
|
|
3401
|
-
adapt(req,
|
|
3411
|
+
adapt(req, res) {
|
|
3402
3412
|
const headers = this.parseHeaders(req.headers);
|
|
3403
3413
|
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3404
|
-
return this.createXenoWebTransport(url, req.method, headers, req.body);
|
|
3414
|
+
return this.createXenoWebTransport(url, req.method, headers, req.body, res);
|
|
3405
3415
|
}
|
|
3406
3416
|
handleHeaderChange(res, name, value, action) {
|
|
3407
3417
|
if (action === "delete") {
|
|
@@ -4744,6 +4754,7 @@ __export(index_exports, {
|
|
|
4744
4754
|
BaseAuthorizationStrategy: () => BaseAuthorizationStrategy,
|
|
4745
4755
|
BaseController: () => BaseController,
|
|
4746
4756
|
BaseHandler: () => BaseHandler,
|
|
4757
|
+
BaseHttpAdapter: () => BaseHttpAdapter,
|
|
4747
4758
|
BasePostgresSqlDataSource: () => BasePostgresSqlDataSource,
|
|
4748
4759
|
BaseQuery: () => Query,
|
|
4749
4760
|
BaseSqliteSqlDataSource: () => BaseSqliteSqlDataSource,
|
|
@@ -5054,7 +5065,7 @@ var AppBuilder = class {
|
|
|
5054
5065
|
custom: void 0
|
|
5055
5066
|
};
|
|
5056
5067
|
_pipelineConfig = {
|
|
5057
|
-
performance: { thresholdMs: 500 },
|
|
5068
|
+
performance: { thresholdMs: 500, intentThresholdMs: void 0 },
|
|
5058
5069
|
authorization: {
|
|
5059
5070
|
policies: void 0,
|
|
5060
5071
|
customAuthorizationStrategy: void 0
|
|
@@ -5575,6 +5586,7 @@ import { AppError as AppError15, Result as Result16 } from "@xeno-js/shared";
|
|
|
5575
5586
|
|
|
5576
5587
|
// src/infrastructure/index.ts
|
|
5577
5588
|
init_factories();
|
|
5589
|
+
init_http();
|
|
5578
5590
|
init_idempotency();
|
|
5579
5591
|
|
|
5580
5592
|
// src/infrastructure/loggers/index.ts
|
|
@@ -5696,6 +5708,7 @@ export {
|
|
|
5696
5708
|
BaseAuthorizationStrategy,
|
|
5697
5709
|
BaseController,
|
|
5698
5710
|
BaseHandler,
|
|
5711
|
+
BaseHttpAdapter,
|
|
5699
5712
|
BasePostgresSqlDataSource,
|
|
5700
5713
|
Query as BaseQuery,
|
|
5701
5714
|
BaseSqliteSqlDataSource,
|