@olane/o-core 0.7.31 → 0.7.34

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.
@@ -32,6 +32,14 @@ export declare class CoreUtils extends oObject {
32
32
  * @param stream - The stream to send the response through
33
33
  */
34
34
  static sendResponse(response: oResponse, stream: Stream): Promise<void>;
35
+ /**
36
+ * Sends a response through a stream using length-prefixed encoding
37
+ * Uses lpStream for proper message boundaries (libp2p v3 best practice)
38
+ *
39
+ * @param response - The response to send
40
+ * @param stream - The stream to send the response through
41
+ */
42
+ static sendResponseLP(response: oResponse, stream: Stream): Promise<void>;
35
43
  /**
36
44
  * @deprecated Use sendResponse instead - both methods are now identical
37
45
  * Sends a streaming response through a stream
@@ -39,6 +47,15 @@ export declare class CoreUtils extends oObject {
39
47
  */
40
48
  static sendStreamResponse(response: oResponse, stream: Stream): Promise<void>;
41
49
  static processStream(event: any): Promise<any>;
50
+ /**
51
+ * Processes a length-prefixed stream event
52
+ * With length-prefixing, messages are guaranteed to be complete and not concatenated
53
+ * This eliminates the need for the '}{' splitting hack
54
+ *
55
+ * @param event - The stream event containing message data
56
+ * @returns The parsed message object
57
+ */
58
+ static processStreamLP(event: any): Promise<any>;
42
59
  static processStreamRequest(event: any): Promise<oRequest>;
43
60
  static processStreamResponse(event: any): Promise<oResponse>;
44
61
  static toCID(data: any): Promise<CID>;
@@ -1 +1 @@
1
- {"version":3,"file":"core.utils.d.ts","sourceRoot":"","sources":["../../../src/utils/core.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAGP,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,OAAO,EAAE,OAAO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AItD,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA6B3D;;;;;;;OAOG;WACiB,eAAe,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;WAsBzC,oBAAoB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;WAKnD,qBAAqB,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC;WAQrD,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAMnD"}
@@ -1,4 +1,4 @@
1
- import { generateKeyPairFromSeed, createEd25519PeerId, Uint8ArrayList, } from '@olane/o-config';
1
+ import { generateKeyPairFromSeed, createEd25519PeerId, Uint8ArrayList, lpStream, } from '@olane/o-config';
2
2
  import { createHash } from 'crypto';
3
3
  import { oAddress } from '../router/o-address.js';
4
4
  import { oResponse } from '../connection/o-response.js';
@@ -95,6 +95,28 @@ export class CoreUtils extends oObject {
95
95
  utils.logger.error('Error sending response: ', error);
96
96
  }
97
97
  }
98
+ /**
99
+ * Sends a response through a stream using length-prefixed encoding
100
+ * Uses lpStream for proper message boundaries (libp2p v3 best practice)
101
+ *
102
+ * @param response - The response to send
103
+ * @param stream - The stream to send the response through
104
+ */
105
+ static async sendResponseLP(response, stream) {
106
+ const utils = new CoreUtils();
107
+ if (!stream || stream.status !== 'open') {
108
+ utils.logger.warn('Stream is not open. Status: ' + (stream?.status || 'undefined'));
109
+ return;
110
+ }
111
+ try {
112
+ const lp = lpStream(stream);
113
+ const data = new TextEncoder().encode(response.toString());
114
+ await lp.write(data);
115
+ }
116
+ catch (error) {
117
+ utils.logger.error('Error sending length-prefixed response: ', error);
118
+ }
119
+ }
98
120
  /**
99
121
  * @deprecated Use sendResponse instead - both methods are now identical
100
122
  * Sends a streaming response through a stream
@@ -125,6 +147,32 @@ export class CoreUtils extends oObject {
125
147
  return decoded;
126
148
  }
127
149
  }
150
+ /**
151
+ * Processes a length-prefixed stream event
152
+ * With length-prefixing, messages are guaranteed to be complete and not concatenated
153
+ * This eliminates the need for the '}{' splitting hack
154
+ *
155
+ * @param event - The stream event containing message data
156
+ * @returns The parsed message object
157
+ */
158
+ static async processStreamLP(event) {
159
+ const bytes = event.data instanceof Uint8ArrayList ? event.data.subarray() : event.data;
160
+ const decoded = new TextDecoder().decode(bytes);
161
+ const utils = new CoreUtils();
162
+ try {
163
+ // With length-prefixing, no need to check for concatenated messages
164
+ if (decoded.startsWith('{')) {
165
+ return JSON.parse(decoded);
166
+ }
167
+ else {
168
+ return decoded;
169
+ }
170
+ }
171
+ catch (error) {
172
+ utils.logger.error('[ERROR] Error processing length-prefixed stream event: ', error, decoded);
173
+ return decoded;
174
+ }
175
+ }
128
176
  static async processStreamRequest(event) {
129
177
  const req = await CoreUtils.processStream(event);
130
178
  return new oRequest(req);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-core",
3
- "version": "0.7.31",
3
+ "version": "0.7.34",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -63,12 +63,12 @@
63
63
  "typescript": "^5.8.3"
64
64
  },
65
65
  "dependencies": {
66
- "@olane/o-protocol": "0.7.31",
66
+ "@olane/o-protocol": "0.7.34",
67
67
  "chalk": "^5.4.1",
68
68
  "debug": "^4.4.1",
69
69
  "dotenv": "^16.5.0",
70
70
  "multiformats": "^13.3.7",
71
71
  "stream-json": "^1.9.1"
72
72
  },
73
- "gitHead": "a17496faa38e2c7680ea774f76d96bce07246f78"
73
+ "gitHead": "f5c2e654d18505174074f2df972c1e4851eb7ea3"
74
74
  }