@asenajs/ergenecore 1.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +636 -0
  3. package/dist/index.d.ts +24 -0
  4. package/dist/index.js +25 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/Ergenecore.d.ts +598 -0
  7. package/dist/lib/Ergenecore.js +1406 -0
  8. package/dist/lib/Ergenecore.js.map +1 -0
  9. package/dist/lib/ErgenecoreContextWrapper.d.ts +190 -0
  10. package/dist/lib/ErgenecoreContextWrapper.js +387 -0
  11. package/dist/lib/ErgenecoreContextWrapper.js.map +1 -0
  12. package/dist/lib/ErgenecoreWebsocketAdapter.d.ts +68 -0
  13. package/dist/lib/ErgenecoreWebsocketAdapter.js +233 -0
  14. package/dist/lib/ErgenecoreWebsocketAdapter.js.map +1 -0
  15. package/dist/lib/defaults/ConfigService.d.ts +39 -0
  16. package/dist/lib/defaults/ConfigService.js +30 -0
  17. package/dist/lib/defaults/ConfigService.js.map +1 -0
  18. package/dist/lib/defaults/MiddlewareService.d.ts +39 -0
  19. package/dist/lib/defaults/MiddlewareService.js +30 -0
  20. package/dist/lib/defaults/MiddlewareService.js.map +1 -0
  21. package/dist/lib/defaults/StaticServeService.d.ts +24 -0
  22. package/dist/lib/defaults/StaticServeService.js +23 -0
  23. package/dist/lib/defaults/StaticServeService.js.map +1 -0
  24. package/dist/lib/defaults/ValidationService.d.ts +35 -0
  25. package/dist/lib/defaults/ValidationService.js +34 -0
  26. package/dist/lib/defaults/ValidationService.js.map +1 -0
  27. package/dist/lib/defaults/index.d.ts +25 -0
  28. package/dist/lib/defaults/index.js +26 -0
  29. package/dist/lib/defaults/index.js.map +1 -0
  30. package/dist/lib/errors.d.ts +84 -0
  31. package/dist/lib/errors.js +108 -0
  32. package/dist/lib/errors.js.map +1 -0
  33. package/dist/lib/index.d.ts +36 -0
  34. package/dist/lib/index.js +37 -0
  35. package/dist/lib/index.js.map +1 -0
  36. package/dist/lib/middlewares/CorsMiddleware.d.ts +147 -0
  37. package/dist/lib/middlewares/CorsMiddleware.js +163 -0
  38. package/dist/lib/middlewares/CorsMiddleware.js.map +1 -0
  39. package/dist/lib/middlewares/RateLimiterMiddleware.d.ts +330 -0
  40. package/dist/lib/middlewares/RateLimiterMiddleware.js +300 -0
  41. package/dist/lib/middlewares/RateLimiterMiddleware.js.map +1 -0
  42. package/dist/lib/types/Handler.d.ts +65 -0
  43. package/dist/lib/types/Handler.js +10 -0
  44. package/dist/lib/types/Handler.js.map +1 -0
  45. package/dist/lib/types/StaticServeExtras.d.ts +29 -0
  46. package/dist/lib/types/StaticServeExtras.js +2 -0
  47. package/dist/lib/types/StaticServeExtras.js.map +1 -0
  48. package/dist/lib/types/Validation.d.ts +7 -0
  49. package/dist/lib/types/Validation.js +2 -0
  50. package/dist/lib/types/Validation.js.map +1 -0
  51. package/dist/lib/types/index.d.ts +24 -0
  52. package/dist/lib/types/index.js +25 -0
  53. package/dist/lib/types/index.js.map +1 -0
  54. package/dist/lib/utils/factory.d.ts +121 -0
  55. package/dist/lib/utils/factory.js +144 -0
  56. package/dist/lib/utils/factory.js.map +1 -0
  57. package/package.json +47 -0
@@ -0,0 +1,68 @@
1
+ import { AsenaWebsocketAdapter } from '@asenajs/asena/adapter';
2
+ import type { ServerLogger } from '@asenajs/asena/logger';
3
+ import type { Server } from 'bun';
4
+ import type { AsenaWebSocketService } from '@asenajs/asena/web-socket';
5
+ import { type WSOptions } from '@asenajs/asena/web-socket';
6
+ /**
7
+ * CoreWebsocketAdapter - WebSocket adapter for Bun
8
+ *
9
+ * Uses Bun's native WebSocket API with namespace-based routing
10
+ */
11
+ export declare class ErgenecoreWebsocketAdapter extends AsenaWebsocketAdapter {
12
+ name: string;
13
+ private activeConnections;
14
+ private connectionLimits;
15
+ private heartbeatIntervals;
16
+ constructor(logger: ServerLogger);
17
+ /**
18
+ * Registers a WebSocket service with namespace (base class implementation)
19
+ * @param webSocketService - WebSocket service to register
20
+ */
21
+ registerWebSocket(webSocketService: AsenaWebSocketService<any>): void;
22
+ /**
23
+ * Sets maximum connections allowed per namespace
24
+ * @param namespace - WebSocket namespace
25
+ * @param limit - Maximum number of concurrent connections
26
+ */
27
+ setConnectionLimit(namespace: string, limit: number): void;
28
+ /**
29
+ * Gets active connection count for a namespace
30
+ * @param namespace - WebSocket namespace
31
+ * @returns Number of active connections
32
+ */
33
+ getConnectionCount(namespace: string): number;
34
+ /**
35
+ * Graceful shutdown - closes all connections
36
+ * @param _timeoutMs - Timeout for graceful shutdown (default: 5000)
37
+ */
38
+ shutdown(_timeoutMs?: number): Promise<void>;
39
+ /**
40
+ * Prepares WebSocket configuration with lifecycle handlers
41
+ * @param options - WebSocket options
42
+ */
43
+ prepareWebSocket(options?: WSOptions & {
44
+ heartbeatInterval?: number;
45
+ }): void;
46
+ /**
47
+ * Starts WebSocket server and initializes AsenaWebSocketServer for each namespace
48
+ * @param server - Bun Server instance
49
+ */
50
+ startWebsocket(server: Server<any>): void;
51
+ /**
52
+ * Starts heartbeat for a connection
53
+ * @param ws - WebSocket connection
54
+ * @param intervalMs - Heartbeat interval in milliseconds (default: 30000)
55
+ */
56
+ private startHeartbeat;
57
+ /**
58
+ * Stops heartbeat for a connection
59
+ * @param connectionId - Connection ID
60
+ */
61
+ private stopHeartbeat;
62
+ /**
63
+ * Creates a handler wrapper for WebSocket lifecycle events
64
+ * @param type - Event type (onOpenInternal, onMessage, etc.)
65
+ * @returns Handler function
66
+ */
67
+ private createHandler;
68
+ }
@@ -0,0 +1,233 @@
1
+ import { AsenaWebsocketAdapter } from '@asenajs/asena/adapter';
2
+ import { AsenaSocket, AsenaWebSocketServer, } from '@asenajs/asena/web-socket';
3
+ /**
4
+ * CoreWebsocketAdapter - WebSocket adapter for Bun
5
+ *
6
+ * Uses Bun's native WebSocket API with namespace-based routing
7
+ */
8
+ export class ErgenecoreWebsocketAdapter extends AsenaWebsocketAdapter {
9
+ name = 'ErgenecoreWebsocketAdapter';
10
+ activeConnections = new Map(); // namespace -> Set of connection IDs
11
+ connectionLimits = new Map(); // namespace -> max connections
12
+ heartbeatIntervals = new Map(); // connection ID -> interval
13
+ constructor(logger) {
14
+ super(logger);
15
+ }
16
+ /**
17
+ * Registers a WebSocket service with namespace (base class implementation)
18
+ * @param webSocketService - WebSocket service to register
19
+ */
20
+ registerWebSocket(webSocketService) {
21
+ if (!webSocketService) {
22
+ throw new Error('WebSocket service is required');
23
+ }
24
+ if (!webSocketService.namespace) {
25
+ throw new Error('WebSocket namespace is required');
26
+ }
27
+ // Validate namespace format: alphanumeric, hyphens, underscores, and slashes allowed
28
+ const namespaceRegex = /^[a-zA-Z0-9/_-]+$/;
29
+ if (!namespaceRegex.test(webSocketService.namespace)) {
30
+ throw new Error(`Invalid WebSocket namespace format: "${webSocketService.namespace}". Only alphanumeric characters, hyphens, underscores, and slashes are allowed.`);
31
+ }
32
+ // Initialize websockets map if needed
33
+ if (this._websockets === undefined) {
34
+ this._websockets = new Map();
35
+ }
36
+ // Check for duplicate registration
37
+ if (this._websockets.has(webSocketService.namespace)) {
38
+ this.logger.warn(`WebSocket namespace "${webSocketService.namespace}" is already registered. Overwriting previous registration...`);
39
+ }
40
+ this._websockets.set(webSocketService.namespace, webSocketService);
41
+ }
42
+ /**
43
+ * Sets maximum connections allowed per namespace
44
+ * @param namespace - WebSocket namespace
45
+ * @param limit - Maximum number of concurrent connections
46
+ */
47
+ setConnectionLimit(namespace, limit) {
48
+ if (limit < 1) {
49
+ throw new Error('Connection limit must be at least 1');
50
+ }
51
+ this.connectionLimits.set(namespace, limit);
52
+ this.logger.info(`Connection limit set for namespace "${namespace}": ${limit}`);
53
+ }
54
+ /**
55
+ * Gets active connection count for a namespace
56
+ * @param namespace - WebSocket namespace
57
+ * @returns Number of active connections
58
+ */
59
+ getConnectionCount(namespace) {
60
+ return this.activeConnections.get(namespace)?.size || 0;
61
+ }
62
+ /**
63
+ * Graceful shutdown - closes all connections
64
+ * @param _timeoutMs - Timeout for graceful shutdown (default: 5000)
65
+ */
66
+ async shutdown(_timeoutMs = 5000) {
67
+ this.logger.info('Starting WebSocket graceful shutdown...');
68
+ // Stop all heartbeats
69
+ for (const interval of this.heartbeatIntervals.values()) {
70
+ clearInterval(interval);
71
+ }
72
+ this.heartbeatIntervals.clear();
73
+ // Clear connection tracking
74
+ this.activeConnections.clear();
75
+ this.logger.info('WebSocket shutdown complete');
76
+ }
77
+ /**
78
+ * Prepares WebSocket configuration with lifecycle handlers
79
+ * @param options - WebSocket options
80
+ */
81
+ prepareWebSocket(options) {
82
+ if (!this.websockets || this.websockets.size < 1) {
83
+ return;
84
+ }
85
+ const heartbeatInterval = options?.heartbeatInterval;
86
+ this.websocket = {
87
+ open: (ws) => {
88
+ // Normalize to namespace format (remove leading /)
89
+ const namespace = ws.data.path.replace(/^\//, '');
90
+ // Check connection limit
91
+ const limit = this.connectionLimits.get(namespace);
92
+ const currentCount = this.getConnectionCount(namespace);
93
+ if (limit && currentCount >= limit) {
94
+ this.logger.warn(`Connection limit reached for namespace "${namespace}": ${currentCount}/${limit}. Rejecting new connection.`);
95
+ ws.close(1008, 'Connection limit reached');
96
+ return;
97
+ }
98
+ // Track connection
99
+ if (!this.activeConnections.has(namespace)) {
100
+ this.activeConnections.set(namespace, new Set());
101
+ }
102
+ this.activeConnections.get(namespace).add(ws.data.id);
103
+ // Start heartbeat if enabled
104
+ if (heartbeatInterval) {
105
+ this.startHeartbeat(ws, heartbeatInterval);
106
+ }
107
+ this.logger.info(`WebSocket opened: ${ws.data.id} on namespace "${namespace}" (${currentCount + 1} active connections)`);
108
+ // Call user handler
109
+ this.createHandler('onOpenInternal')(ws);
110
+ },
111
+ close: (ws, code, reason) => {
112
+ // Normalize to namespace format (remove leading /)
113
+ const namespace = ws.data.path.replace(/^\//, '');
114
+ // Stop heartbeat
115
+ this.stopHeartbeat(ws.data.id);
116
+ // Remove from tracking
117
+ this.activeConnections.get(namespace)?.delete(ws.data.id);
118
+ const remainingCount = this.getConnectionCount(namespace);
119
+ this.logger.info(`WebSocket closed: ${ws.data.id} on namespace "${namespace}" (${remainingCount} remaining connections)`);
120
+ // Call user handler
121
+ this.createHandler('onCloseInternal')(ws, code, reason);
122
+ },
123
+ message: this.createHandler('onMessage'),
124
+ drain: this.createHandler('onDrain'),
125
+ ping: this.createHandler('onPing'),
126
+ pong: this.createHandler('onPong'),
127
+ ...options,
128
+ };
129
+ }
130
+ /**
131
+ * Starts WebSocket server and initializes AsenaWebSocketServer for each namespace
132
+ * @param server - Bun Server instance
133
+ */
134
+ startWebsocket(server) {
135
+ if (!this.websockets || this.websockets.size < 1) {
136
+ return;
137
+ }
138
+ for (const [namespace, websocket] of this.websockets) {
139
+ websocket.server = new AsenaWebSocketServer(server, namespace);
140
+ }
141
+ }
142
+ /**
143
+ * Starts heartbeat for a connection
144
+ * @param ws - WebSocket connection
145
+ * @param intervalMs - Heartbeat interval in milliseconds (default: 30000)
146
+ */
147
+ startHeartbeat(ws, intervalMs = 30000) {
148
+ const interval = setInterval(() => {
149
+ if (ws.readyState === WebSocket.OPEN) {
150
+ try {
151
+ ws.ping();
152
+ }
153
+ catch (error) {
154
+ this.logger.error(`Heartbeat ping failed for connection ${ws.data.id}:`, error);
155
+ this.stopHeartbeat(ws.data.id);
156
+ if (ws.readyState === WebSocket.OPEN) {
157
+ ws.close(1011, 'Heartbeat failed');
158
+ }
159
+ }
160
+ }
161
+ else {
162
+ this.stopHeartbeat(ws.data.id);
163
+ }
164
+ }, intervalMs);
165
+ this.heartbeatIntervals.set(ws.data.id, interval);
166
+ }
167
+ /**
168
+ * Stops heartbeat for a connection
169
+ * @param connectionId - Connection ID
170
+ */
171
+ stopHeartbeat(connectionId) {
172
+ const interval = this.heartbeatIntervals.get(connectionId);
173
+ if (interval) {
174
+ clearInterval(interval);
175
+ this.heartbeatIntervals.delete(connectionId);
176
+ }
177
+ }
178
+ /**
179
+ * Creates a handler wrapper for WebSocket lifecycle events
180
+ * @param type - Event type (onOpenInternal, onMessage, etc.)
181
+ * @returns Handler function
182
+ */
183
+ createHandler(type) {
184
+ return async (ws, ...args) => {
185
+ const websocket = this.websockets.get(ws.data.path);
186
+ if (!websocket) {
187
+ this.logger.error(`WebSocket handler not found for path: ${ws.data.path}`);
188
+ // Close connection with error code if handler not found
189
+ if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
190
+ ws.close(1011, 'Internal server error: handler not found');
191
+ }
192
+ return;
193
+ }
194
+ let handler = websocket[type];
195
+ if (!handler) {
196
+ // Not all handlers are required, so this is not an error
197
+ return;
198
+ }
199
+ handler = handler.bind(websocket);
200
+ try {
201
+ await handler(new AsenaSocket(ws, websocket), ...args);
202
+ }
203
+ catch (error) {
204
+ this.logger.error(`WebSocket ${type} handler error for path ${ws.data.path}:`, {
205
+ error: error instanceof Error ? error.message : String(error),
206
+ stack: error instanceof Error ? error.stack : undefined,
207
+ socketId: ws.data.id,
208
+ path: ws.data.path,
209
+ });
210
+ // Try to send error to client if connection is still open
211
+ if (ws.readyState === WebSocket.OPEN) {
212
+ try {
213
+ ws.send(JSON.stringify({
214
+ type: 'error',
215
+ message: 'Server error occurred',
216
+ timestamp: new Date().toISOString(),
217
+ }));
218
+ }
219
+ catch (sendError) {
220
+ this.logger.error('Failed to send error message to client:', sendError);
221
+ }
222
+ }
223
+ // For critical errors, close connection gracefully
224
+ if (type === 'onOpenInternal' || type === 'onMessage') {
225
+ if (ws.readyState === WebSocket.OPEN) {
226
+ ws.close(1011, 'Handler error');
227
+ }
228
+ }
229
+ }
230
+ };
231
+ }
232
+ }
233
+ //# sourceMappingURL=ErgenecoreWebsocketAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErgenecoreWebsocketAdapter.js","sourceRoot":"","sources":["../../lib/ErgenecoreWebsocketAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,OAAO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K,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;oBACvD,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE;oBACpB,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI;iBACnB,CAAC,CAAC;gBAEH,0DAA0D;gBAC1D,IAAI,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;oBACrC,IAAI,CAAC;wBACH,EAAE,CAAC,IAAI,CACL,IAAI,CAAC,SAAS,CAAC;4BACb,IAAI,EAAE,OAAO;4BACb,OAAO,EAAE,uBAAuB;4BAChC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;yBACpC,CAAC,CACH,CAAC;oBACJ,CAAC;oBAAC,OAAO,SAAS,EAAE,CAAC;wBACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE,SAAS,CAAC,CAAC;oBAC1E,CAAC;gBACH,CAAC;gBAED,mDAAmD;gBACnD,IAAI,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;oBACtD,IAAI,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;wBACrC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;oBAClC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CAEF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Ergenecore ConfigService
3
+ *
4
+ * Base class for configuration services in Ergenecore adapter.
5
+ * Extends Asena's config service interface with Ergenecore-specific Context type.
6
+ *
7
+ * @module defaults/ConfigService
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Config } from '@asenajs/asena/server';
12
+ * import { ConfigService, type Context } from '@asenajs/ergenecore';
13
+ *
14
+ * @Config()
15
+ * export class ServerConfig extends ConfigService {
16
+ * onError(error: Error, context: Context): Response {
17
+ * return context.send({ error: error.message }, 500);
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ import type { AsenaConfig } from '@asenajs/asena/server/config';
23
+ import type { Context } from '../ErgenecoreContextWrapper';
24
+ /**
25
+ * Base class for Ergenecore configuration services
26
+ *
27
+ * Implements Asena's config service interface with Ergenecore's Context type.
28
+ * Use this to define global error handlers and other server configuration.
29
+ */
30
+ export declare abstract class ConfigService implements AsenaConfig<Context> {
31
+ /**
32
+ * Global error handler
33
+ *
34
+ * @param error - The error that occurred
35
+ * @param context - Ergenecore context wrapper
36
+ * @returns Response or Promise<Response>
37
+ */
38
+ abstract onError(error: Error, context: Context): Response | Promise<Response>;
39
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Ergenecore ConfigService
3
+ *
4
+ * Base class for configuration services in Ergenecore adapter.
5
+ * Extends Asena's config service interface with Ergenecore-specific Context type.
6
+ *
7
+ * @module defaults/ConfigService
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Config } from '@asenajs/asena/server';
12
+ * import { ConfigService, type Context } from '@asenajs/ergenecore';
13
+ *
14
+ * @Config()
15
+ * export class ServerConfig extends ConfigService {
16
+ * onError(error: Error, context: Context): Response {
17
+ * return context.send({ error: error.message }, 500);
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ /**
23
+ * Base class for Ergenecore configuration services
24
+ *
25
+ * Implements Asena's config service interface with Ergenecore's Context type.
26
+ * Use this to define global error handlers and other server configuration.
27
+ */
28
+ export class ConfigService {
29
+ }
30
+ //# sourceMappingURL=ConfigService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigService.js","sourceRoot":"","sources":["../../../lib/defaults/ConfigService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH;;;;;GAKG;AACH,MAAM,OAAgB,aAAa;CAWlC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Ergenecore MiddlewareService
3
+ *
4
+ * Base class for middleware services in Ergenecore adapter.
5
+ * Extends Asena's middleware service interface with Ergenecore-specific Context type.
6
+ *
7
+ * @module defaults/MiddlewareService
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Middleware } from '@asenajs/asena/server';
12
+ * import { MiddlewareService, type Context } from '@asenajs/ergenecore';
13
+ *
14
+ * @Middleware()
15
+ * export class AuthMiddleware extends MiddlewareService {
16
+ * async handle(context: Context, next: () => Promise<void>) {
17
+ * // Your middleware logic
18
+ * await next();
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ import type { AsenaMiddlewareService } from '@asenajs/asena/middleware';
24
+ import type { Context } from '../ErgenecoreContextWrapper';
25
+ /**
26
+ * Base class for Ergenecore middleware services
27
+ *
28
+ * Implements Asena's middleware service interface with Ergenecore's Context type.
29
+ */
30
+ export declare abstract class MiddlewareService implements AsenaMiddlewareService<Context> {
31
+ /**
32
+ * Middleware handler
33
+ *
34
+ * @param context - Ergenecore context wrapper
35
+ * @param next - Function to call next middleware or handler
36
+ * @returns Promise that resolves when middleware completes
37
+ */
38
+ abstract handle(context: Context, next: () => Promise<void>): Promise<any>;
39
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Ergenecore MiddlewareService
3
+ *
4
+ * Base class for middleware services in Ergenecore adapter.
5
+ * Extends Asena's middleware service interface with Ergenecore-specific Context type.
6
+ *
7
+ * @module defaults/MiddlewareService
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Middleware } from '@asenajs/asena/server';
12
+ * import { MiddlewareService, type Context } from '@asenajs/ergenecore';
13
+ *
14
+ * @Middleware()
15
+ * export class AuthMiddleware extends MiddlewareService {
16
+ * async handle(context: Context, next: () => Promise<void>) {
17
+ * // Your middleware logic
18
+ * await next();
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ /**
24
+ * Base class for Ergenecore middleware services
25
+ *
26
+ * Implements Asena's middleware service interface with Ergenecore's Context type.
27
+ */
28
+ export class MiddlewareService {
29
+ }
30
+ //# sourceMappingURL=MiddlewareService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MiddlewareService.js","sourceRoot":"","sources":["../../../lib/defaults/MiddlewareService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH;;;;GAIG;AACH,MAAM,OAAgB,iBAAiB;CAWtC"}
@@ -0,0 +1,24 @@
1
+ import { AsenaStaticServeService } from '@asenajs/asena/middleware';
2
+ import type { StaticServeExtras } from '../types';
3
+ import type { Context } from '../ErgenecoreContextWrapper';
4
+ /**
5
+ * Base class for static file serving services in Ergenecore adapter
6
+ *
7
+ * Extends AsenaStaticServeService with Ergenecore-specific Context and StaticServeExtras types
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { StaticServe } from '@asenajs/asena/server';
12
+ * import { StaticServeService } from '@asenajs/ergenecore';
13
+ * import path from 'path';
14
+ *
15
+ * @StaticServe({ root: path.join(process.cwd(), 'public') })
16
+ * export class MyStaticServe extends StaticServeService {
17
+ * public rewriteRequestPath(reqPath: string): string {
18
+ * return reqPath.replace(/^\/static/, '');
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ export declare abstract class StaticServeService extends AsenaStaticServeService<Context, StaticServeExtras> {
24
+ }
@@ -0,0 +1,23 @@
1
+ import { AsenaStaticServeService } from '@asenajs/asena/middleware';
2
+ /**
3
+ * Base class for static file serving services in Ergenecore adapter
4
+ *
5
+ * Extends AsenaStaticServeService with Ergenecore-specific Context and StaticServeExtras types
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { StaticServe } from '@asenajs/asena/server';
10
+ * import { StaticServeService } from '@asenajs/ergenecore';
11
+ * import path from 'path';
12
+ *
13
+ * @StaticServe({ root: path.join(process.cwd(), 'public') })
14
+ * export class MyStaticServe extends StaticServeService {
15
+ * public rewriteRequestPath(reqPath: string): string {
16
+ * return reqPath.replace(/^\/static/, '');
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ export class StaticServeService extends AsenaStaticServeService {
22
+ }
23
+ //# sourceMappingURL=StaticServeService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StaticServeService.js","sourceRoot":"","sources":["../../../lib/defaults/StaticServeService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAIpE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,uBAAmD;CAAG"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Ergenecore ValidationService
3
+ *
4
+ * Base class for validation services in Ergenecore adapter.
5
+ * Extends Asena's validation service interface with Ergenecore-specific types.
6
+ *
7
+ * @module defaults/ValidationService
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Middleware } from '@asenajs/asena/server';
12
+ * import { ValidationService } from '@asenajs/ergenecore';
13
+ * import { z } from 'zod';
14
+ *
15
+ * @Middleware({ validator: true })
16
+ * export class CreateUserValidator extends ValidationService {
17
+ * json() {
18
+ * return z.object({
19
+ * name: z.string().min(3),
20
+ * email: z.string().email()
21
+ * });
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ import type { AsenaValidationService } from '@asenajs/asena/middleware';
27
+ import type { ValidationSchema, ValidationSchemaWithHook } from '../types';
28
+ /**
29
+ * Base class for Ergenecore validation services
30
+ *
31
+ * Implements Asena's validation service interface with support for
32
+ * Zod schemas and custom validation hooks.
33
+ */
34
+ export declare abstract class ValidationService implements AsenaValidationService<ValidationSchema | ValidationSchemaWithHook> {
35
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Ergenecore ValidationService
3
+ *
4
+ * Base class for validation services in Ergenecore adapter.
5
+ * Extends Asena's validation service interface with Ergenecore-specific types.
6
+ *
7
+ * @module defaults/ValidationService
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Middleware } from '@asenajs/asena/server';
12
+ * import { ValidationService } from '@asenajs/ergenecore';
13
+ * import { z } from 'zod';
14
+ *
15
+ * @Middleware({ validator: true })
16
+ * export class CreateUserValidator extends ValidationService {
17
+ * json() {
18
+ * return z.object({
19
+ * name: z.string().min(3),
20
+ * email: z.string().email()
21
+ * });
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ /**
27
+ * Base class for Ergenecore validation services
28
+ *
29
+ * Implements Asena's validation service interface with support for
30
+ * Zod schemas and custom validation hooks.
31
+ */
32
+ export class ValidationService {
33
+ }
34
+ //# sourceMappingURL=ValidationService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationService.js","sourceRoot":"","sources":["../../../lib/defaults/ValidationService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH;;;;;GAKG;AACH,MAAM,OAAgB,iBAAiB;CAC4C"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Ergenecore Defaults
3
+ *
4
+ * Export adapter-specific base classes for common services.
5
+ * These classes provide type-safe implementations of Asena's service interfaces
6
+ * with Ergenecore's Context type.
7
+ *
8
+ * @module defaults
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import {
13
+ * ValidationService,
14
+ * ConfigService,
15
+ * MiddlewareService,
16
+ * type Context
17
+ * } from '@asenajs/ergenecore';
18
+ * ```
19
+ */
20
+ export { ValidationService } from './ValidationService';
21
+ export { ConfigService } from './ConfigService';
22
+ export { MiddlewareService } from './MiddlewareService';
23
+ export { StaticServeService } from './StaticServeService';
24
+ export { CorsMiddleware, type CorsOptions } from '../middlewares/CorsMiddleware';
25
+ export { RateLimiterMiddleware, type RateLimiterOptions } from '../middlewares/RateLimiterMiddleware';
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Ergenecore Defaults
3
+ *
4
+ * Export adapter-specific base classes for common services.
5
+ * These classes provide type-safe implementations of Asena's service interfaces
6
+ * with Ergenecore's Context type.
7
+ *
8
+ * @module defaults
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import {
13
+ * ValidationService,
14
+ * ConfigService,
15
+ * MiddlewareService,
16
+ * type Context
17
+ * } from '@asenajs/ergenecore';
18
+ * ```
19
+ */
20
+ export { ValidationService } from './ValidationService';
21
+ export { ConfigService } from './ConfigService';
22
+ export { MiddlewareService } from './MiddlewareService';
23
+ export { StaticServeService } from './StaticServeService';
24
+ export { CorsMiddleware } from '../middlewares/CorsMiddleware';
25
+ export { RateLimiterMiddleware } from '../middlewares/RateLimiterMiddleware';
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/defaults/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAoB,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAA2B,MAAM,sCAAsC,CAAC"}