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/dist/router.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.PeerRouter = void 0;
|
|
|
13
13
|
const utils_1 = require("./utils");
|
|
14
14
|
const entity_1 = require("./entity");
|
|
15
15
|
const path_to_regexp_1 = require("path-to-regexp");
|
|
16
|
-
//
|
|
16
|
+
// Enhanced router with advanced features
|
|
17
17
|
class PeerRouter {
|
|
18
18
|
constructor() {
|
|
19
19
|
this.routeCache = new Map();
|
|
@@ -35,7 +35,7 @@ class PeerRouter {
|
|
|
35
35
|
post(path, callback) {
|
|
36
36
|
this.add({ path, method: 'POST', callback });
|
|
37
37
|
}
|
|
38
|
-
//
|
|
38
|
+
// Enhanced middleware support with priority
|
|
39
39
|
use(handler, prefix = '', options = {}) {
|
|
40
40
|
this.middleware.push({
|
|
41
41
|
path: prefix + '/{*postfix}',
|
|
@@ -46,7 +46,7 @@ class PeerRouter {
|
|
|
46
46
|
// Sort middleware by priority (higher priority first)
|
|
47
47
|
this.middleware.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
48
48
|
}
|
|
49
|
-
//
|
|
49
|
+
// Enhanced middleware composition with error handling
|
|
50
50
|
compose(middlewares) {
|
|
51
51
|
return (conn, message) => __awaiter(this, void 0, void 0, function* () {
|
|
52
52
|
let index = -1;
|
|
@@ -73,7 +73,7 @@ class PeerRouter {
|
|
|
73
73
|
return dispatch(0);
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
-
//
|
|
76
|
+
// Enhanced route execution with caching and monitoring
|
|
77
77
|
run(conn, message) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
79
|
const routeKey = `${message.method}:${message.route}`;
|
|
@@ -137,7 +137,7 @@ class PeerRouter {
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
-
//
|
|
140
|
+
// Route statistics tracking
|
|
141
141
|
updateRouteStats(routeKey, type, value) {
|
|
142
142
|
const stats = this.routeStats.get(routeKey) || { calls: 0, avgResponseTime: 0, errors: 0 };
|
|
143
143
|
switch (type) {
|
|
@@ -155,7 +155,7 @@ class PeerRouter {
|
|
|
155
155
|
}
|
|
156
156
|
this.routeStats.set(routeKey, stats);
|
|
157
157
|
}
|
|
158
|
-
//
|
|
158
|
+
// Get router statistics
|
|
159
159
|
getRouterStats() {
|
|
160
160
|
return {
|
|
161
161
|
totalRoutes: this.routes.length,
|
|
@@ -165,11 +165,11 @@ class PeerRouter {
|
|
|
165
165
|
cacheSize: this.routeCache.size,
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
|
-
//
|
|
168
|
+
// Clear route cache
|
|
169
169
|
clearCache() {
|
|
170
170
|
this.routeCache.clear();
|
|
171
171
|
}
|
|
172
|
-
//
|
|
172
|
+
// Get route information
|
|
173
173
|
getRouteInfo(path, method) {
|
|
174
174
|
const route = this.routes.find((r) => r.path === path && r.method === method);
|
|
175
175
|
if (!route)
|
|
@@ -177,7 +177,7 @@ class PeerRouter {
|
|
|
177
177
|
const stats = this.routeStats.get(`${method}:${path}`);
|
|
178
178
|
return Object.assign(Object.assign({}, route), { stats });
|
|
179
179
|
}
|
|
180
|
-
//
|
|
180
|
+
// Health check
|
|
181
181
|
healthCheck() {
|
|
182
182
|
return {
|
|
183
183
|
status: 'healthy',
|
package/package.json
CHANGED
package/src/handler.ts
CHANGED
|
@@ -62,7 +62,7 @@ export class Handler {
|
|
|
62
62
|
body: message.body,
|
|
63
63
|
createdAt: message.createdAt,
|
|
64
64
|
action: PeerAction.RECEIVE,
|
|
65
|
-
status: MessageStatus.DONE,
|
|
65
|
+
status: message.body?.status || MessageStatus.DONE,
|
|
66
66
|
};
|
|
67
67
|
await handler.process(data);
|
|
68
68
|
await transfer.responseOk(conn, message);
|