nextrush 2.0.0 → 2.0.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.
- package/README.md +54 -20
- package/dist/index.d.mts +737 -9
- package/dist/index.d.ts +737 -9
- package/dist/index.js +5 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
import { IncomingMessage, ServerResponse, Server } from 'node:http';
|
|
2
3
|
import { ParsedUrlQuery } from 'node:querystring';
|
|
3
4
|
import { EventEmitter } from 'node:events';
|
|
4
5
|
|
|
@@ -628,12 +629,6 @@ interface NextRushResponse$1 extends ServerResponse {
|
|
|
628
629
|
lastModified(date: Date): NextRushResponse$1;
|
|
629
630
|
}
|
|
630
631
|
|
|
631
|
-
/**
|
|
632
|
-
* Koa-style context types for NextRush v2
|
|
633
|
-
*
|
|
634
|
-
* @packageDocumentation
|
|
635
|
-
*/
|
|
636
|
-
|
|
637
632
|
/**
|
|
638
633
|
* WebSocket connection interface
|
|
639
634
|
*/
|
|
@@ -1030,7 +1025,7 @@ interface Application {
|
|
|
1030
1025
|
listen(port?: number, callback?: () => void): unknown;
|
|
1031
1026
|
listen(port?: number, host?: string, callback?: () => void): unknown;
|
|
1032
1027
|
/** Get the underlying HTTP server */
|
|
1033
|
-
getServer():
|
|
1028
|
+
getServer(): http.Server;
|
|
1034
1029
|
/** Gracefully shutdown the application */
|
|
1035
1030
|
shutdown(): Promise<void>;
|
|
1036
1031
|
/** Create CORS middleware */
|
|
@@ -1478,12 +1473,745 @@ declare class StreamTransport implements Transport {
|
|
|
1478
1473
|
write(entry: LogEntry): void;
|
|
1479
1474
|
}
|
|
1480
1475
|
|
|
1476
|
+
/**
|
|
1477
|
+
* NextRush v2 Event System Types
|
|
1478
|
+
*
|
|
1479
|
+
* Comprehensive type-safe event system with CQRS patterns,
|
|
1480
|
+
* event sourcing, and pipeline processing capabilities.
|
|
1481
|
+
*
|
|
1482
|
+
* @version 2.0.0
|
|
1483
|
+
* @author NextRush Core Team
|
|
1484
|
+
*/
|
|
1485
|
+
|
|
1486
|
+
/**
|
|
1487
|
+
* Base metadata for all events
|
|
1488
|
+
*/
|
|
1489
|
+
interface BaseEventMetadata {
|
|
1490
|
+
/** Unique event ID */
|
|
1491
|
+
readonly id: string;
|
|
1492
|
+
/** Event timestamp in milliseconds */
|
|
1493
|
+
readonly timestamp: number;
|
|
1494
|
+
/** Event correlation ID for tracing */
|
|
1495
|
+
readonly correlationId?: string;
|
|
1496
|
+
/** User/system that triggered the event */
|
|
1497
|
+
readonly source: string;
|
|
1498
|
+
/** Event version for evolution */
|
|
1499
|
+
readonly version: number;
|
|
1500
|
+
/** Additional custom metadata */
|
|
1501
|
+
readonly [key: string]: unknown;
|
|
1502
|
+
}
|
|
1503
|
+
/**
|
|
1504
|
+
* Generic Event interface with full type safety
|
|
1505
|
+
*
|
|
1506
|
+
* @template TType - Event type identifier
|
|
1507
|
+
* @template TData - Event payload data
|
|
1508
|
+
* @template TMetadata - Additional event metadata
|
|
1509
|
+
*/
|
|
1510
|
+
interface Event<TType extends string = string, TData = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> {
|
|
1511
|
+
/** Event type identifier */
|
|
1512
|
+
readonly type: TType;
|
|
1513
|
+
/** Event payload data */
|
|
1514
|
+
readonly data: TData;
|
|
1515
|
+
/** Event metadata */
|
|
1516
|
+
readonly metadata: TMetadata;
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Command interface for CQRS pattern
|
|
1520
|
+
* Commands represent intent to change state
|
|
1521
|
+
*/
|
|
1522
|
+
interface Command<TType extends string = string, TData = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> extends Event<TType, TData, TMetadata> {
|
|
1523
|
+
/** Command should be processed exactly once */
|
|
1524
|
+
readonly idempotencyKey?: string;
|
|
1525
|
+
/** Command execution timeout in milliseconds */
|
|
1526
|
+
readonly timeout?: number;
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Query interface for CQRS pattern
|
|
1530
|
+
* Queries represent intent to read state
|
|
1531
|
+
*/
|
|
1532
|
+
interface Query<TType extends string = string, TData = unknown, TResult = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> extends Event<TType, TData, TMetadata> {
|
|
1533
|
+
/** Expected result type (for type inference) */
|
|
1534
|
+
readonly _resultType?: TResult;
|
|
1535
|
+
}
|
|
1536
|
+
/**
|
|
1537
|
+
* Domain Event for business logic events
|
|
1538
|
+
*/
|
|
1539
|
+
interface DomainEvent<TType extends string = string, TData = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> extends Event<TType, TData, TMetadata> {
|
|
1540
|
+
/** Aggregate ID that produced this event */
|
|
1541
|
+
readonly aggregateId: string;
|
|
1542
|
+
/** Aggregate type */
|
|
1543
|
+
readonly aggregateType: string;
|
|
1544
|
+
/** Event sequence number for ordering */
|
|
1545
|
+
readonly sequenceNumber: number;
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Event handler function type
|
|
1549
|
+
*/
|
|
1550
|
+
type EventHandler<T extends Event = Event> = (event: T, context?: Context) => Promise<void> | void;
|
|
1551
|
+
/**
|
|
1552
|
+
* Event handler with metadata
|
|
1553
|
+
*/
|
|
1554
|
+
interface EventHandlerDefinition<T extends Event = Event> {
|
|
1555
|
+
/** Handler function */
|
|
1556
|
+
readonly handler: EventHandler<T>;
|
|
1557
|
+
/** Handler priority (lower = higher priority) */
|
|
1558
|
+
readonly priority?: number;
|
|
1559
|
+
/** Handler should run only once */
|
|
1560
|
+
readonly once?: boolean;
|
|
1561
|
+
/** Handler timeout in milliseconds */
|
|
1562
|
+
readonly timeout?: number;
|
|
1563
|
+
/** Handler retry configuration */
|
|
1564
|
+
readonly retry?: {
|
|
1565
|
+
readonly maxAttempts: number;
|
|
1566
|
+
readonly delay: number;
|
|
1567
|
+
readonly backoffMultiplier?: number;
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Event pipeline middleware function
|
|
1572
|
+
*/
|
|
1573
|
+
type EventPipelineMiddleware<T extends Event = Event> = (event: T, next: () => Promise<void>) => Promise<void> | void;
|
|
1574
|
+
/**
|
|
1575
|
+
* Event transformer function
|
|
1576
|
+
*/
|
|
1577
|
+
type EventTransformer<TInput extends Event, TOutput extends Event> = (event: TInput) => Promise<TOutput> | TOutput;
|
|
1578
|
+
/**
|
|
1579
|
+
* Event filter predicate
|
|
1580
|
+
*/
|
|
1581
|
+
type EventFilter<T extends Event = Event> = (event: T) => boolean | Promise<boolean>;
|
|
1582
|
+
/**
|
|
1583
|
+
* Event pipeline stage
|
|
1584
|
+
*/
|
|
1585
|
+
interface EventPipelineStage<T extends Event = Event> {
|
|
1586
|
+
/** Stage name */
|
|
1587
|
+
readonly name: string;
|
|
1588
|
+
/** Stage middleware */
|
|
1589
|
+
readonly middleware?: EventPipelineMiddleware<T>[];
|
|
1590
|
+
/** Event transformers */
|
|
1591
|
+
readonly transformers?: EventTransformer<T, T>[];
|
|
1592
|
+
/** Event filters */
|
|
1593
|
+
readonly filters?: EventFilter<T>[];
|
|
1594
|
+
/** Stage timeout in milliseconds */
|
|
1595
|
+
readonly timeout?: number;
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* Event pipeline configuration
|
|
1599
|
+
*/
|
|
1600
|
+
interface EventPipelineConfig<T extends Event = Event> {
|
|
1601
|
+
/** Pipeline name */
|
|
1602
|
+
readonly name: string;
|
|
1603
|
+
/** Pipeline stages */
|
|
1604
|
+
readonly stages: EventPipelineStage<T>[];
|
|
1605
|
+
/** Error handling strategy */
|
|
1606
|
+
readonly errorHandling?: 'stop' | 'continue' | 'retry';
|
|
1607
|
+
/** Pipeline timeout in milliseconds */
|
|
1608
|
+
readonly timeout?: number;
|
|
1609
|
+
/** Enable performance monitoring */
|
|
1610
|
+
readonly monitoring?: boolean;
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Event subscription handle
|
|
1614
|
+
*/
|
|
1615
|
+
interface EventSubscription {
|
|
1616
|
+
/** Subscription ID */
|
|
1617
|
+
readonly id: string;
|
|
1618
|
+
/** Unsubscribe from events */
|
|
1619
|
+
unsubscribe(): Promise<void>;
|
|
1620
|
+
/** Check if subscription is active */
|
|
1621
|
+
isActive(): boolean;
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Event store statistics
|
|
1625
|
+
*/
|
|
1626
|
+
interface EventStoreStats {
|
|
1627
|
+
/** Total events stored */
|
|
1628
|
+
readonly totalEvents: number;
|
|
1629
|
+
/** Events by type */
|
|
1630
|
+
readonly eventsByType: Record<string, number>;
|
|
1631
|
+
/** Storage size in bytes */
|
|
1632
|
+
readonly storageSize: number;
|
|
1633
|
+
/** Last event timestamp */
|
|
1634
|
+
readonly lastEventTimestamp?: number;
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* Event processing metrics
|
|
1638
|
+
*/
|
|
1639
|
+
interface EventMetrics {
|
|
1640
|
+
/** Events emitted by type */
|
|
1641
|
+
readonly eventsEmitted: Record<string, number>;
|
|
1642
|
+
/** Events processed by type */
|
|
1643
|
+
readonly eventsProcessed: Record<string, number>;
|
|
1644
|
+
/** Processing errors by type */
|
|
1645
|
+
readonly processingErrors: Record<string, number>;
|
|
1646
|
+
/** Average processing time by type (ms) */
|
|
1647
|
+
readonly averageProcessingTime: Record<string, number>;
|
|
1648
|
+
/** Pipeline execution stats */
|
|
1649
|
+
readonly pipelineStats: Record<string, PipelineStats>;
|
|
1650
|
+
/** Memory usage stats */
|
|
1651
|
+
readonly memoryUsage: {
|
|
1652
|
+
readonly heapUsed: number;
|
|
1653
|
+
readonly heapTotal: number;
|
|
1654
|
+
readonly external: number;
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
/**
|
|
1658
|
+
* Pipeline execution statistics
|
|
1659
|
+
*/
|
|
1660
|
+
interface PipelineStats {
|
|
1661
|
+
/** Pipeline executions count */
|
|
1662
|
+
readonly executions: number;
|
|
1663
|
+
/** Average execution time (ms) */
|
|
1664
|
+
readonly averageExecutionTime: number;
|
|
1665
|
+
/** Successful executions */
|
|
1666
|
+
readonly successes: number;
|
|
1667
|
+
/** Failed executions */
|
|
1668
|
+
readonly failures: number;
|
|
1669
|
+
/** Stage execution stats */
|
|
1670
|
+
readonly stageStats: Record<string, {
|
|
1671
|
+
readonly executions: number;
|
|
1672
|
+
readonly averageTime: number;
|
|
1673
|
+
readonly failures: number;
|
|
1674
|
+
}>;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* Command handler type
|
|
1679
|
+
*/
|
|
1680
|
+
type CommandHandler<TCommand extends Command, TResult = void> = (command: TCommand) => Promise<TResult> | TResult;
|
|
1681
|
+
/**
|
|
1682
|
+
* Query handler type
|
|
1683
|
+
*/
|
|
1684
|
+
type QueryHandler<TQuery extends Query, TResult = unknown> = (query: TQuery) => Promise<TResult> | TResult;
|
|
1685
|
+
/**
|
|
1686
|
+
* Event system configuration
|
|
1687
|
+
*/
|
|
1688
|
+
interface EventSystemConfig {
|
|
1689
|
+
/** Enable event store persistence */
|
|
1690
|
+
readonly enableEventStore?: boolean;
|
|
1691
|
+
/** Event store type */
|
|
1692
|
+
readonly eventStoreType?: 'memory' | 'persistent';
|
|
1693
|
+
/** Maximum events for in-memory store */
|
|
1694
|
+
readonly maxStoredEvents?: number;
|
|
1695
|
+
/** Enable performance monitoring */
|
|
1696
|
+
readonly enableMonitoring?: boolean;
|
|
1697
|
+
/** Default event handler timeout */
|
|
1698
|
+
readonly defaultTimeout?: number;
|
|
1699
|
+
/** Maximum concurrent event processing */
|
|
1700
|
+
readonly maxConcurrency?: number;
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Complete event system with CQRS and Event Sourcing
|
|
1704
|
+
*/
|
|
1705
|
+
declare class NextRushEventSystem {
|
|
1706
|
+
private readonly eventEmitter;
|
|
1707
|
+
private readonly eventStore?;
|
|
1708
|
+
private readonly commandHandlers;
|
|
1709
|
+
private readonly queryHandlers;
|
|
1710
|
+
private readonly config;
|
|
1711
|
+
private systemSubscriptions;
|
|
1712
|
+
constructor(config?: EventSystemConfig);
|
|
1713
|
+
/**
|
|
1714
|
+
* Emit an event
|
|
1715
|
+
*/
|
|
1716
|
+
emit<T extends Event>(event: T): Promise<void>;
|
|
1717
|
+
/**
|
|
1718
|
+
* Create and emit an event
|
|
1719
|
+
*/
|
|
1720
|
+
emitEvent<T extends Event>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): Promise<void>;
|
|
1721
|
+
/**
|
|
1722
|
+
* Create and emit a domain event
|
|
1723
|
+
*/
|
|
1724
|
+
emitDomainEvent<T extends DomainEvent>(type: T['type'], data: T['data'], aggregateId: string, aggregateType: string, sequenceNumber: number, metadata?: Partial<BaseEventMetadata>): Promise<void>;
|
|
1725
|
+
/**
|
|
1726
|
+
* Subscribe to events
|
|
1727
|
+
*/
|
|
1728
|
+
subscribe<T extends Event>(eventType: string, handler: EventHandler<T>): EventSubscription;
|
|
1729
|
+
/**
|
|
1730
|
+
* Subscribe with options
|
|
1731
|
+
*/
|
|
1732
|
+
subscribeWithOptions<T extends Event>(eventType: string, definition: EventHandlerDefinition<T>): EventSubscription;
|
|
1733
|
+
/**
|
|
1734
|
+
* Unsubscribe from events
|
|
1735
|
+
*/
|
|
1736
|
+
unsubscribeAll(eventType: string): Promise<void>;
|
|
1737
|
+
/**
|
|
1738
|
+
* Add event pipeline
|
|
1739
|
+
*/
|
|
1740
|
+
addPipeline<T extends Event>(eventType: string, pipeline: EventPipelineConfig<T>): void;
|
|
1741
|
+
/**
|
|
1742
|
+
* Remove event pipeline
|
|
1743
|
+
*/
|
|
1744
|
+
removePipeline(eventType: string, pipelineName: string): void;
|
|
1745
|
+
/**
|
|
1746
|
+
* Get pipeline names
|
|
1747
|
+
*/
|
|
1748
|
+
getPipelineNames(eventType: string): string[];
|
|
1749
|
+
/**
|
|
1750
|
+
* Register command handler
|
|
1751
|
+
*/
|
|
1752
|
+
registerCommandHandler<TCommand extends Command, TResult = void>(commandType: string, handler: CommandHandler<TCommand, TResult>): void;
|
|
1753
|
+
/**
|
|
1754
|
+
* Execute command
|
|
1755
|
+
*/
|
|
1756
|
+
executeCommand<TCommand extends Command, TResult = void>(command: TCommand): Promise<TResult>;
|
|
1757
|
+
/**
|
|
1758
|
+
* Register query handler
|
|
1759
|
+
*/
|
|
1760
|
+
registerQueryHandler<TQuery extends Query, TResult = unknown>(queryType: string, handler: QueryHandler<TQuery, TResult>): void;
|
|
1761
|
+
/**
|
|
1762
|
+
* Execute query
|
|
1763
|
+
*/
|
|
1764
|
+
executeQuery<TQuery extends Query, TResult = unknown>(query: TQuery): Promise<TResult>;
|
|
1765
|
+
/**
|
|
1766
|
+
* Load events for aggregate
|
|
1767
|
+
*/
|
|
1768
|
+
loadAggregateEvents<T extends DomainEvent>(aggregateId: string, options?: {
|
|
1769
|
+
readonly afterSequence?: number;
|
|
1770
|
+
readonly limit?: number;
|
|
1771
|
+
}): Promise<T[]>;
|
|
1772
|
+
/**
|
|
1773
|
+
* Load events by correlation ID
|
|
1774
|
+
*/
|
|
1775
|
+
loadCorrelatedEvents<T extends Event>(correlationId: string, options?: {
|
|
1776
|
+
readonly limit?: number;
|
|
1777
|
+
readonly offset?: number;
|
|
1778
|
+
}): Promise<T[]>;
|
|
1779
|
+
/**
|
|
1780
|
+
* Load events by type
|
|
1781
|
+
*/
|
|
1782
|
+
loadEventsByType<T extends Event>(eventType: string, options?: {
|
|
1783
|
+
readonly after?: Date;
|
|
1784
|
+
readonly before?: Date;
|
|
1785
|
+
readonly limit?: number;
|
|
1786
|
+
readonly offset?: number;
|
|
1787
|
+
}): Promise<T[]>;
|
|
1788
|
+
/**
|
|
1789
|
+
* Get event metrics
|
|
1790
|
+
*/
|
|
1791
|
+
getMetrics(): EventMetrics;
|
|
1792
|
+
/**
|
|
1793
|
+
* Get event store statistics
|
|
1794
|
+
*/
|
|
1795
|
+
getEventStoreStats(): Promise<EventStoreStats>;
|
|
1796
|
+
/**
|
|
1797
|
+
* Get subscription count
|
|
1798
|
+
*/
|
|
1799
|
+
getSubscriptionCount(eventType?: string): number;
|
|
1800
|
+
/**
|
|
1801
|
+
* Enable/disable monitoring
|
|
1802
|
+
*/
|
|
1803
|
+
setMonitoring(enabled: boolean): void;
|
|
1804
|
+
/**
|
|
1805
|
+
* Clear all events and subscriptions
|
|
1806
|
+
*/
|
|
1807
|
+
clear(): Promise<void>;
|
|
1808
|
+
/**
|
|
1809
|
+
* Shutdown the event system
|
|
1810
|
+
*/
|
|
1811
|
+
shutdown(): Promise<void>;
|
|
1812
|
+
/**
|
|
1813
|
+
* Create event with metadata
|
|
1814
|
+
*/
|
|
1815
|
+
createEvent<T extends Event>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): T;
|
|
1816
|
+
/**
|
|
1817
|
+
* Create command with metadata
|
|
1818
|
+
*/
|
|
1819
|
+
createCommand<T extends Command>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): T;
|
|
1820
|
+
/**
|
|
1821
|
+
* Create query with metadata
|
|
1822
|
+
*/
|
|
1823
|
+
createQuery<T extends Query>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): T;
|
|
1824
|
+
/**
|
|
1825
|
+
* Create domain event with aggregate info
|
|
1826
|
+
*/
|
|
1827
|
+
createDomainEvent<T extends DomainEvent>(type: T['type'], data: T['data'], aggregateId: string, aggregateType: string, sequenceNumber: number, metadata?: Partial<BaseEventMetadata>): T;
|
|
1828
|
+
/**
|
|
1829
|
+
* Emit system event
|
|
1830
|
+
*/
|
|
1831
|
+
private emitSystemEvent;
|
|
1832
|
+
/**
|
|
1833
|
+
* Auto-persist events to store
|
|
1834
|
+
*/
|
|
1835
|
+
private persistEventHandler;
|
|
1836
|
+
/**
|
|
1837
|
+
* Generic dispatch method for commands, queries, or events
|
|
1838
|
+
* This provides a unified interface for different operation types
|
|
1839
|
+
*/
|
|
1840
|
+
dispatch<T = any>(operation: Command | Query | Event): Promise<T>;
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
/**
|
|
1844
|
+
* Simple Events API Facade for NextRush v2
|
|
1845
|
+
*
|
|
1846
|
+
* Provides a simple string-based event API that bridges to the sophisticated
|
|
1847
|
+
* CQRS/Event Sourcing implementation underneath.
|
|
1848
|
+
*
|
|
1849
|
+
* @version 2.0.0
|
|
1850
|
+
* @author NextRush Core Team
|
|
1851
|
+
*/
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* Simple event handler type for string-based events
|
|
1855
|
+
*/
|
|
1856
|
+
type SimpleEventHandler = (data: any) => void | Promise<void>;
|
|
1857
|
+
/**
|
|
1858
|
+
* Simple Events API Facade
|
|
1859
|
+
*
|
|
1860
|
+
* Provides familiar Express-style event API while leveraging
|
|
1861
|
+
* the sophisticated CQRS implementation underneath.
|
|
1862
|
+
*/
|
|
1863
|
+
declare class SimpleEventsAPI {
|
|
1864
|
+
private eventSystem;
|
|
1865
|
+
private listeners;
|
|
1866
|
+
constructor(eventSystem: NextRushEventSystem);
|
|
1867
|
+
/**
|
|
1868
|
+
* Emit a simple string-based event
|
|
1869
|
+
*
|
|
1870
|
+
* @param eventName - Event name
|
|
1871
|
+
* @param data - Event data
|
|
1872
|
+
* @returns Promise that resolves when event is processed
|
|
1873
|
+
*
|
|
1874
|
+
* @example
|
|
1875
|
+
* ```typescript
|
|
1876
|
+
* app.events.emit('user.created', { userId: '123', name: 'John' });
|
|
1877
|
+
* ```
|
|
1878
|
+
*/
|
|
1879
|
+
emit(eventName: string, data?: any): Promise<void>;
|
|
1880
|
+
/**
|
|
1881
|
+
* Listen for a simple string-based event
|
|
1882
|
+
*
|
|
1883
|
+
* @param eventName - Event name to listen for
|
|
1884
|
+
* @param handler - Handler function
|
|
1885
|
+
* @returns Unsubscribe function
|
|
1886
|
+
*
|
|
1887
|
+
* @example
|
|
1888
|
+
* ```typescript
|
|
1889
|
+
* const unsubscribe = app.events.on('user.created', (data) => {
|
|
1890
|
+
* console.log('User created:', data.userId);
|
|
1891
|
+
* });
|
|
1892
|
+
* ```
|
|
1893
|
+
*/
|
|
1894
|
+
on(eventName: string, handler: SimpleEventHandler): () => void;
|
|
1895
|
+
/**
|
|
1896
|
+
* Listen for a simple string-based event (once)
|
|
1897
|
+
*
|
|
1898
|
+
* @param eventName - Event name to listen for
|
|
1899
|
+
* @param handler - Handler function
|
|
1900
|
+
* @returns Promise that resolves with event data
|
|
1901
|
+
*
|
|
1902
|
+
* @example
|
|
1903
|
+
* ```typescript
|
|
1904
|
+
* const data = await app.events.once('user.created');
|
|
1905
|
+
* console.log('User created:', data.userId);
|
|
1906
|
+
* ```
|
|
1907
|
+
*/
|
|
1908
|
+
once(eventName: string, handler?: SimpleEventHandler): Promise<any>;
|
|
1909
|
+
/**
|
|
1910
|
+
* Remove all listeners for an event
|
|
1911
|
+
*
|
|
1912
|
+
* @param eventName - Event name
|
|
1913
|
+
*
|
|
1914
|
+
* @example
|
|
1915
|
+
* ```typescript
|
|
1916
|
+
* app.events.off('user.created');
|
|
1917
|
+
* ```
|
|
1918
|
+
*/
|
|
1919
|
+
off(eventName: string): void;
|
|
1920
|
+
/**
|
|
1921
|
+
* Remove all listeners
|
|
1922
|
+
*
|
|
1923
|
+
* @example
|
|
1924
|
+
* ```typescript
|
|
1925
|
+
* app.events.removeAllListeners();
|
|
1926
|
+
* ```
|
|
1927
|
+
*/
|
|
1928
|
+
removeAllListeners(): void;
|
|
1929
|
+
/**
|
|
1930
|
+
* Get list of event names that have listeners
|
|
1931
|
+
*
|
|
1932
|
+
* @returns Array of event names
|
|
1933
|
+
*/
|
|
1934
|
+
eventNames(): string[];
|
|
1935
|
+
/**
|
|
1936
|
+
* Get number of listeners for an event
|
|
1937
|
+
*
|
|
1938
|
+
* @param eventName - Event name
|
|
1939
|
+
* @returns Number of listeners
|
|
1940
|
+
*/
|
|
1941
|
+
listenerCount(eventName: string): number;
|
|
1942
|
+
/**
|
|
1943
|
+
* Get maximum number of listeners (for compatibility)
|
|
1944
|
+
* Returns Infinity as we don't impose limits
|
|
1945
|
+
*/
|
|
1946
|
+
getMaxListeners(): number;
|
|
1947
|
+
/**
|
|
1948
|
+
* Set maximum number of listeners (for compatibility)
|
|
1949
|
+
* No-op as we don't impose limits
|
|
1950
|
+
*/
|
|
1951
|
+
setMaxListeners(_n: number): this;
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1481
1954
|
/**
|
|
1482
1955
|
* Core Application class for NextRush v2
|
|
1483
1956
|
*
|
|
1484
1957
|
* @packageDocumentation
|
|
1485
1958
|
*/
|
|
1486
1959
|
|
|
1960
|
+
/**
|
|
1961
|
+
* NextRush Application class with Koa-style middleware and Express-like design
|
|
1962
|
+
*
|
|
1963
|
+
* @example
|
|
1964
|
+
* ```typescript
|
|
1965
|
+
* import { createApp } from 'nextrush-v2';
|
|
1966
|
+
*
|
|
1967
|
+
* const app = createApp({ port: 3000 });
|
|
1968
|
+
*
|
|
1969
|
+
* app.use(async (ctx, next) => {
|
|
1970
|
+
* console.log(`${ctx.method} ${ctx.path}`);
|
|
1971
|
+
* await next();
|
|
1972
|
+
* });
|
|
1973
|
+
*
|
|
1974
|
+
* app.get('/hello', async (ctx) => {
|
|
1975
|
+
* ctx.res.json({ message: 'Hello, World!' });
|
|
1976
|
+
* });
|
|
1977
|
+
*
|
|
1978
|
+
* app.listen(3000, () => {
|
|
1979
|
+
* console.log('Server running on http://localhost:3000');
|
|
1980
|
+
* });
|
|
1981
|
+
* ```
|
|
1982
|
+
*/
|
|
1983
|
+
declare class NextRushApplication extends EventEmitter implements Application {
|
|
1984
|
+
private server;
|
|
1985
|
+
private middleware;
|
|
1986
|
+
private internalRouter;
|
|
1987
|
+
private options;
|
|
1988
|
+
private isShuttingDown;
|
|
1989
|
+
private container;
|
|
1990
|
+
private middlewareFactory;
|
|
1991
|
+
private compiler;
|
|
1992
|
+
private cachedExceptionFilter;
|
|
1993
|
+
private static readonly EXCEPTION_FILTER_MARK;
|
|
1994
|
+
private _eventSystem;
|
|
1995
|
+
private _simpleEvents;
|
|
1996
|
+
constructor(options?: ApplicationOptions);
|
|
1997
|
+
/**
|
|
1998
|
+
* Create HTTP server
|
|
1999
|
+
*/
|
|
2000
|
+
private createServer;
|
|
2001
|
+
/**
|
|
2002
|
+
* Setup event handlers
|
|
2003
|
+
*/
|
|
2004
|
+
private setupEventHandlers;
|
|
2005
|
+
/**
|
|
2006
|
+
* Get cached exception filter or scan once and cache it
|
|
2007
|
+
*/
|
|
2008
|
+
private getOrFindExceptionFilter;
|
|
2009
|
+
/**
|
|
2010
|
+
* Handle incoming requests
|
|
2011
|
+
*/
|
|
2012
|
+
private handleRequest;
|
|
2013
|
+
/**
|
|
2014
|
+
* Execute middleware stack.
|
|
2015
|
+
* - Production: run directly on ctx for maximum performance.
|
|
2016
|
+
* - Debug mode: wrap with SafeContext for diagnostics.
|
|
2017
|
+
*/
|
|
2018
|
+
private executeMiddlewareWithBoundary;
|
|
2019
|
+
/**
|
|
2020
|
+
* Execute route handler with high-performance direct execution
|
|
2021
|
+
*/
|
|
2022
|
+
private executeRouteWithBoundary;
|
|
2023
|
+
/**
|
|
2024
|
+
* Register GET route
|
|
2025
|
+
*/
|
|
2026
|
+
get(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2027
|
+
/**
|
|
2028
|
+
* Register POST route
|
|
2029
|
+
*/
|
|
2030
|
+
post(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2031
|
+
/**
|
|
2032
|
+
* Register PUT route
|
|
2033
|
+
*/
|
|
2034
|
+
put(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2035
|
+
/**
|
|
2036
|
+
* Register DELETE route
|
|
2037
|
+
*/
|
|
2038
|
+
delete(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2039
|
+
/**
|
|
2040
|
+
* Register PATCH route
|
|
2041
|
+
*/
|
|
2042
|
+
patch(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2043
|
+
/**
|
|
2044
|
+
* Register middleware or sub-router
|
|
2045
|
+
*/
|
|
2046
|
+
use(middleware: Middleware): this;
|
|
2047
|
+
use(prefix: string, router: Router): this;
|
|
2048
|
+
/**
|
|
2049
|
+
* Create router instance
|
|
2050
|
+
*/
|
|
2051
|
+
router(): Router;
|
|
2052
|
+
/**
|
|
2053
|
+
* Register a route with the router
|
|
2054
|
+
*/
|
|
2055
|
+
private registerRoute;
|
|
2056
|
+
/**
|
|
2057
|
+
* Start the server
|
|
2058
|
+
*/
|
|
2059
|
+
listen(port?: number, callback?: () => void): Server;
|
|
2060
|
+
listen(port?: number, host?: string, callback?: () => void): Server;
|
|
2061
|
+
/**
|
|
2062
|
+
* Get the underlying HTTP server
|
|
2063
|
+
*/
|
|
2064
|
+
getServer(): Server;
|
|
2065
|
+
/**
|
|
2066
|
+
* Get simple events API for Express-style event handling
|
|
2067
|
+
*
|
|
2068
|
+
* @example
|
|
2069
|
+
* ```typescript
|
|
2070
|
+
* app.events.emit('user.created', { userId: '123' });
|
|
2071
|
+
* app.events.on('user.created', (data) => console.log(data));
|
|
2072
|
+
* ```
|
|
2073
|
+
*/
|
|
2074
|
+
get events(): SimpleEventsAPI;
|
|
2075
|
+
/**
|
|
2076
|
+
* Get advanced event system for CQRS and Event Sourcing
|
|
2077
|
+
*
|
|
2078
|
+
* @example
|
|
2079
|
+
* ```typescript
|
|
2080
|
+
* app.eventSystem.dispatch(new CreateUserCommand({ name: 'John' }));
|
|
2081
|
+
* app.eventSystem.subscribe(UserCreatedEvent, handler);
|
|
2082
|
+
* ```
|
|
2083
|
+
*/
|
|
2084
|
+
get eventSystem(): NextRushEventSystem;
|
|
2085
|
+
/**
|
|
2086
|
+
* Gracefully shutdown the application
|
|
2087
|
+
*/
|
|
2088
|
+
shutdown(): Promise<void>;
|
|
2089
|
+
/**
|
|
2090
|
+
* Create CORS middleware - now delegated to middleware factory
|
|
2091
|
+
*/
|
|
2092
|
+
cors(options?: CorsOptions): Middleware;
|
|
2093
|
+
/**
|
|
2094
|
+
* Create helmet middleware - now delegated to middleware factory
|
|
2095
|
+
*/
|
|
2096
|
+
helmet(options?: HelmetOptions): Middleware;
|
|
2097
|
+
/**
|
|
2098
|
+
* Create JSON body parser middleware - now delegated to middleware factory
|
|
2099
|
+
*/
|
|
2100
|
+
json(options?: EnhancedBodyParserOptions): Middleware;
|
|
2101
|
+
/**
|
|
2102
|
+
* Create URL-encoded body parser middleware - now delegated to middleware factory
|
|
2103
|
+
*/
|
|
2104
|
+
urlencoded(options?: EnhancedBodyParserOptions): Middleware;
|
|
2105
|
+
/**
|
|
2106
|
+
* Create text body parser middleware - now delegated to middleware factory
|
|
2107
|
+
*/
|
|
2108
|
+
text(options?: EnhancedBodyParserOptions): Middleware;
|
|
2109
|
+
/**
|
|
2110
|
+
* Create rate limiter middleware - now delegated to middleware factory
|
|
2111
|
+
*/
|
|
2112
|
+
rateLimit(options?: RateLimiterOptions): Middleware;
|
|
2113
|
+
/**
|
|
2114
|
+
* Create logger middleware - now delegated to middleware factory
|
|
2115
|
+
*/
|
|
2116
|
+
logger(options?: LoggerOptions): Middleware;
|
|
2117
|
+
/**
|
|
2118
|
+
* Create compression middleware - now delegated to middleware factory
|
|
2119
|
+
*/
|
|
2120
|
+
compression(options?: CompressionOptions): Middleware;
|
|
2121
|
+
/**
|
|
2122
|
+
* Create request ID middleware - now delegated to middleware factory
|
|
2123
|
+
*/
|
|
2124
|
+
requestId(options?: RequestIdOptions): Middleware;
|
|
2125
|
+
/**
|
|
2126
|
+
* Create timer middleware - now delegated to middleware factory
|
|
2127
|
+
*/
|
|
2128
|
+
timer(options?: TimerOptions): Middleware;
|
|
2129
|
+
/**
|
|
2130
|
+
* Create smart body parser middleware - now delegated to middleware factory
|
|
2131
|
+
*/
|
|
2132
|
+
smartBodyParser(options?: EnhancedBodyParserOptions): Middleware;
|
|
2133
|
+
/**
|
|
2134
|
+
* Create exception filter middleware
|
|
2135
|
+
*
|
|
2136
|
+
* Provides NestJS-style exception handling with custom error classes
|
|
2137
|
+
* and automatic error response formatting.
|
|
2138
|
+
*
|
|
2139
|
+
* @param filters - Array of exception filters to use
|
|
2140
|
+
* @returns Exception filter middleware function
|
|
2141
|
+
*
|
|
2142
|
+
* @example
|
|
2143
|
+
* ```typescript
|
|
2144
|
+
* const app = createApp();
|
|
2145
|
+
*
|
|
2146
|
+
* // Global exception filter
|
|
2147
|
+
* app.use(app.exceptionFilter());
|
|
2148
|
+
*
|
|
2149
|
+
* // With custom filters
|
|
2150
|
+
* app.use(app.exceptionFilter([
|
|
2151
|
+
* new ValidationExceptionFilter(),
|
|
2152
|
+
* new AuthenticationExceptionFilter(),
|
|
2153
|
+
* new GlobalExceptionFilter()
|
|
2154
|
+
* ]));
|
|
2155
|
+
* ```
|
|
2156
|
+
*/
|
|
2157
|
+
exceptionFilter(filters?: ExceptionFilter[]): Middleware;
|
|
2158
|
+
/**
|
|
2159
|
+
* Create advanced logger plugin
|
|
2160
|
+
*
|
|
2161
|
+
* Provides comprehensive logging capabilities similar to Winston/Pino
|
|
2162
|
+
* with multiple transports, structured logging, and performance optimization.
|
|
2163
|
+
*
|
|
2164
|
+
* @param config - Logger configuration options
|
|
2165
|
+
* @returns Logger plugin instance
|
|
2166
|
+
*
|
|
2167
|
+
* @example
|
|
2168
|
+
* ```typescript
|
|
2169
|
+
* const app = createApp();
|
|
2170
|
+
*
|
|
2171
|
+
* // Development logger
|
|
2172
|
+
* const logger = app.createLogger({
|
|
2173
|
+
* level: 'debug',
|
|
2174
|
+
* requestLogging: true,
|
|
2175
|
+
* performance: true
|
|
2176
|
+
* });
|
|
2177
|
+
* logger.install(app);
|
|
2178
|
+
*
|
|
2179
|
+
* // Use logger in routes
|
|
2180
|
+
* app.get('/users', ctx => {
|
|
2181
|
+
* app.logger.info('Fetching users', { userId: ctx.params.id });
|
|
2182
|
+
* ctx.res.json({ users: [] });
|
|
2183
|
+
* });
|
|
2184
|
+
* ```
|
|
2185
|
+
*/
|
|
2186
|
+
createLogger(config?: {
|
|
2187
|
+
level?: 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly';
|
|
2188
|
+
transports?: any[];
|
|
2189
|
+
format?: 'json' | 'text' | 'combined';
|
|
2190
|
+
colorize?: boolean;
|
|
2191
|
+
timestamp?: boolean;
|
|
2192
|
+
context?: string;
|
|
2193
|
+
requestLogging?: boolean;
|
|
2194
|
+
performance?: boolean;
|
|
2195
|
+
structured?: boolean;
|
|
2196
|
+
}): LoggerPlugin;
|
|
2197
|
+
private convertLogLevel;
|
|
2198
|
+
/**
|
|
2199
|
+
* Create development logger
|
|
2200
|
+
*
|
|
2201
|
+
* Optimized for development with debug level, colors, and detailed logging.
|
|
2202
|
+
*
|
|
2203
|
+
* @returns Development logger plugin
|
|
2204
|
+
*/
|
|
2205
|
+
createDevLogger(): LoggerPlugin;
|
|
2206
|
+
/**
|
|
2207
|
+
* Create production logger
|
|
2208
|
+
*
|
|
2209
|
+
* Optimized for production with info level, JSON format, and file logging.
|
|
2210
|
+
*
|
|
2211
|
+
* @returns Production logger plugin
|
|
2212
|
+
*/
|
|
2213
|
+
createProdLogger(): LoggerPlugin;
|
|
2214
|
+
}
|
|
1487
2215
|
/**
|
|
1488
2216
|
* Create a new NextRush application instance
|
|
1489
2217
|
*
|
|
@@ -2313,4 +3041,4 @@ declare const _default: {
|
|
|
2313
3041
|
readonly NODE_VERSION: ">=18.0.0";
|
|
2314
3042
|
};
|
|
2315
3043
|
|
|
2316
|
-
export { type Application, AuthenticationError, AuthenticationExceptionFilter, AuthorizationError, AuthorizationExceptionFilter, BadRequestError, ConflictError, ConsoleTransport, type Context, DatabaseError, type DotfilesPolicy, ErrorFactory, type ExceptionFilter, FileTransport, ForbiddenError, GlobalExceptionFilter, HttpTransport, InternalServerError, type LogEntry, LogLevel, type LoggerConfig, LoggerPlugin, MethodNotAllowedError, type Middleware, NODE_VERSION, NetworkError, type Next, NextRushError, type NextRushRequest, type NextRushResponse$1 as NextRushResponse, NotFoundError, NotFoundExceptionFilter, RateLimitError, RateLimitExceptionFilter, RequestEnhancer, ResponseEnhancer, type RouteConfig, type RouteHandler, type Router, ServiceUnavailableError, type StaticFilesOptions, StaticFilesPlugin, type StatsLike, StreamTransport, type TemplateHelper, TemplatePlugin, type TemplatePluginOptions, type TemplateRenderOptions, TimeoutError, TooManyRequestsError, type Transport, UnauthorizedError, UnprocessableEntityError, VERSION, ValidationError, ValidationExceptionFilter, type WSConnection, type WSContext, type WSHandler, type WSMiddleware, type WebSocketApplication, WebSocketPlugin, type WebSocketPluginOptions, smartBodyParser as bodyParser, compression, cors, createApp, createContext, createDevLogger, createMinimalLogger, createProdLogger, createOptimizedRouter as createRouter, _default as default, hasWebSocketSupport, helmet, logger, rateLimit, requestId, timer, withWebSocket };
|
|
3044
|
+
export { type Application, AuthenticationError, AuthenticationExceptionFilter, AuthorizationError, AuthorizationExceptionFilter, BadRequestError, ConflictError, ConsoleTransport, type Context, DatabaseError, type DotfilesPolicy, ErrorFactory, type ExceptionFilter, FileTransport, ForbiddenError, GlobalExceptionFilter, HttpTransport, InternalServerError, type LogEntry, LogLevel, type LoggerConfig, LoggerPlugin, MethodNotAllowedError, type Middleware, NODE_VERSION, NetworkError, type Next, NextRushApplication, NextRushError, type NextRushRequest, type NextRushResponse$1 as NextRushResponse, NotFoundError, NotFoundExceptionFilter, RateLimitError, RateLimitExceptionFilter, RequestEnhancer, ResponseEnhancer, type RouteConfig, type RouteHandler, type Router, ServiceUnavailableError, type StaticFilesOptions, StaticFilesPlugin, type StatsLike, StreamTransport, type TemplateHelper, TemplatePlugin, type TemplatePluginOptions, type TemplateRenderOptions, TimeoutError, TooManyRequestsError, type Transport, UnauthorizedError, UnprocessableEntityError, VERSION, ValidationError, ValidationExceptionFilter, type WSConnection, type WSContext, type WSHandler, type WSMiddleware, type WebSocketApplication, WebSocketPlugin, type WebSocketPluginOptions, smartBodyParser as bodyParser, compression, cors, createApp, createContext, createDevLogger, createMinimalLogger, createProdLogger, createOptimizedRouter as createRouter, _default as default, hasWebSocketSupport, helmet, logger, rateLimit, requestId, timer, withWebSocket };
|