egos-transfer 0.2.3 → 0.2.4
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/CLAUDE.md +79 -0
- package/dist/handler.js +2 -1
- package/dist/index.d.ts +34 -8
- package/dist/index.js +314 -198
- package/dist/router.js +9 -9
- package/package.json +1 -1
- package/src/handler.ts +1 -1
- package/src/index.ts +369 -206
- package/src/router.ts +9 -9
package/src/router.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { DataConnection } from 'peerjs';
|
|
|
5
5
|
import { TransferErrorCode } from './entity';
|
|
6
6
|
import { match } from 'path-to-regexp';
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// Enhanced router with advanced features
|
|
9
9
|
export class PeerRouter {
|
|
10
10
|
protected routes: RouteItem[];
|
|
11
11
|
protected middleware: MiddlewareItem[];
|
|
@@ -45,7 +45,7 @@ export class PeerRouter {
|
|
|
45
45
|
this.add({ path, method: 'POST', callback });
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
//
|
|
48
|
+
// Enhanced middleware support with priority
|
|
49
49
|
use(
|
|
50
50
|
handler: RequestCallbackFn,
|
|
51
51
|
prefix = '',
|
|
@@ -62,7 +62,7 @@ export class PeerRouter {
|
|
|
62
62
|
this.middleware.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
//
|
|
65
|
+
// Enhanced middleware composition with error handling
|
|
66
66
|
compose(
|
|
67
67
|
middlewares: MiddlewareItem[],
|
|
68
68
|
): (conn: DataConnection, message: PeerMessage) => Promise<[DataConnection, PeerMessage] | null> {
|
|
@@ -100,7 +100,7 @@ export class PeerRouter {
|
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
//
|
|
103
|
+
// Enhanced route execution with caching and monitoring
|
|
104
104
|
async run(conn: DataConnection, message: PeerMessage) {
|
|
105
105
|
const routeKey = `${message.method}:${message.route}`;
|
|
106
106
|
this.performanceMonitor.startTimer(routeKey);
|
|
@@ -175,7 +175,7 @@ export class PeerRouter {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
//
|
|
178
|
+
// Route statistics tracking
|
|
179
179
|
private updateRouteStats(
|
|
180
180
|
routeKey: string,
|
|
181
181
|
type: 'calls' | 'responseTime' | 'errors',
|
|
@@ -200,7 +200,7 @@ export class PeerRouter {
|
|
|
200
200
|
this.routeStats.set(routeKey, stats);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
//
|
|
203
|
+
// Get router statistics
|
|
204
204
|
getRouterStats() {
|
|
205
205
|
return {
|
|
206
206
|
totalRoutes: this.routes.length,
|
|
@@ -211,12 +211,12 @@ export class PeerRouter {
|
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
//
|
|
214
|
+
// Clear route cache
|
|
215
215
|
clearCache() {
|
|
216
216
|
this.routeCache.clear();
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
//
|
|
219
|
+
// Get route information
|
|
220
220
|
getRouteInfo(path: string, method: string) {
|
|
221
221
|
const route = this.routes.find((r) => r.path === path && r.method === method);
|
|
222
222
|
if (!route) return null;
|
|
@@ -228,7 +228,7 @@ export class PeerRouter {
|
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
//
|
|
231
|
+
// Health check
|
|
232
232
|
healthCheck() {
|
|
233
233
|
return {
|
|
234
234
|
status: 'healthy',
|