@olane/o-core 0.7.34 → 0.7.36

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.
@@ -13,7 +13,7 @@ export class oResponse {
13
13
  };
14
14
  }
15
15
  toString() {
16
- return JSON.stringify(this);
16
+ return JSON.stringify(this.toJSON());
17
17
  }
18
18
  static fromJSON(json) {
19
19
  return new oResponse({
@@ -1,7 +1,6 @@
1
1
  import { Stream } from '@olane/o-config';
2
2
  import { oAddress } from '../router/o-address.js';
3
3
  import { oResponse } from '../connection/o-response.js';
4
- import { oRequest } from '../connection/o-request.js';
5
4
  import { CID } from 'multiformats';
6
5
  import { oObject } from '../core/o-object.js';
7
6
  export declare class CoreUtils extends oObject {
@@ -24,14 +23,6 @@ export declare class CoreUtils extends oObject {
24
23
  static phraseToSeedBytes(phrase: string): Uint8Array;
25
24
  static phraseToSeed(phrase: string): string;
26
25
  static childAddress(parentAddress: oAddress, childAddress: oAddress): oAddress;
27
- /**
28
- * Sends a response through a stream
29
- * Consolidated method that handles both regular and streaming responses
30
- *
31
- * @param response - The response to send
32
- * @param stream - The stream to send the response through
33
- */
34
- static sendResponse(response: oResponse, stream: Stream): Promise<void>;
35
26
  /**
36
27
  * Sends a response through a stream using length-prefixed encoding
37
28
  * Uses lpStream for proper message boundaries (libp2p v3 best practice)
@@ -39,25 +30,7 @@ export declare class CoreUtils extends oObject {
39
30
  * @param response - The response to send
40
31
  * @param stream - The stream to send the response through
41
32
  */
42
- static sendResponseLP(response: oResponse, stream: Stream): Promise<void>;
43
- /**
44
- * @deprecated Use sendResponse instead - both methods are now identical
45
- * Sends a streaming response through a stream
46
- * This method is maintained for backward compatibility
47
- */
48
- static sendStreamResponse(response: oResponse, stream: Stream): Promise<void>;
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>;
59
- static processStreamRequest(event: any): Promise<oRequest>;
60
- static processStreamResponse(event: any): Promise<oResponse>;
33
+ static sendResponse(response: oResponse, stream: Stream): Promise<void>;
61
34
  static toCID(data: any): Promise<CID>;
62
35
  }
63
36
  //# sourceMappingURL=core.utils.d.ts.map
@@ -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,EAAE,MAAM,qBAAqB,CAAC;AAE9C,qBAAa,SAAU,SAAQ,OAAO;WACvB,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAK3C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;WAkBvD,WAAW,CAAC,MAAM,EAAE;QAC/B,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;QACrC,OAAO,CAAC,EAAE,QAAQ,CAAC;QACnB,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC;WA4BP,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAQ3D;;;;;;OAMG;WACW,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;WAO7C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAA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M,EAAE;QAC/B,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;QACrC,OAAO,CAAC,EAAE,QAAQ,CAAC;QACnB,IAAI,EAAE,GAAG,CAAC;QACV,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC;WA4BP,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAQ3D;;;;;;OAMG;WACW,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;WAO7C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;WAOpC,YAAY,CACxB,aAAa,EAAE,QAAQ,EACvB,YAAY,EAAE,QAAQ,GACrB,QAAQ;IAIX;;;;;;OAMG;WACiB,YAAY,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;WAmBhD,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAMnD"}
@@ -1,8 +1,6 @@
1
- import { generateKeyPairFromSeed, createEd25519PeerId, Uint8ArrayList, lpStream, } from '@olane/o-config';
1
+ import { generateKeyPairFromSeed, createEd25519PeerId, lpStream, } from '@olane/o-config';
2
2
  import { createHash } from 'crypto';
3
3
  import { oAddress } from '../router/o-address.js';
4
- import { oResponse } from '../connection/o-response.js';
5
- import { oRequest } from '../connection/o-request.js';
6
4
  import { CID } from 'multiformats';
7
5
  import * as json from 'multiformats/codecs/json';
8
6
  import { sha256 } from 'multiformats/hashes/sha2';
@@ -75,26 +73,6 @@ export class CoreUtils extends oObject {
75
73
  static childAddress(parentAddress, childAddress) {
76
74
  return new oAddress(parentAddress.toString() + '/' + childAddress.paths);
77
75
  }
78
- /**
79
- * Sends a response through a stream
80
- * Consolidated method that handles both regular and streaming responses
81
- *
82
- * @param response - The response to send
83
- * @param stream - The stream to send the response through
84
- */
85
- static async sendResponse(response, stream) {
86
- const utils = new CoreUtils();
87
- if (!stream || stream.status !== 'open') {
88
- utils.logger.warn('Stream is not open. Status: ' + (stream?.status || 'undefined'));
89
- return;
90
- }
91
- try {
92
- await stream.send(new TextEncoder().encode(response.toString()));
93
- }
94
- catch (error) {
95
- utils.logger.error('Error sending response: ', error);
96
- }
97
- }
98
76
  /**
99
77
  * Sends a response through a stream using length-prefixed encoding
100
78
  * Uses lpStream for proper message boundaries (libp2p v3 best practice)
@@ -102,7 +80,7 @@ export class CoreUtils extends oObject {
102
80
  * @param response - The response to send
103
81
  * @param stream - The stream to send the response through
104
82
  */
105
- static async sendResponseLP(response, stream) {
83
+ static async sendResponse(response, stream) {
106
84
  const utils = new CoreUtils();
107
85
  if (!stream || stream.status !== 'open') {
108
86
  utils.logger.warn('Stream is not open. Status: ' + (stream?.status || 'undefined'));
@@ -117,73 +95,6 @@ export class CoreUtils extends oObject {
117
95
  utils.logger.error('Error sending length-prefixed response: ', error);
118
96
  }
119
97
  }
120
- /**
121
- * @deprecated Use sendResponse instead - both methods are now identical
122
- * Sends a streaming response through a stream
123
- * This method is maintained for backward compatibility
124
- */
125
- static async sendStreamResponse(response, stream) {
126
- return CoreUtils.sendResponse(response, stream);
127
- }
128
- static async processStream(event) {
129
- const bytes = event.data instanceof Uint8ArrayList ? event.data.subarray() : event.data;
130
- const decoded = new TextDecoder().decode(bytes);
131
- const utils = new CoreUtils();
132
- try {
133
- if (decoded.indexOf('}{') > -1) {
134
- const first = decoded.split('}{')[0] + '}';
135
- utils.logger.warn('Received multiple responses in a single event, returning the first response', first);
136
- return JSON.parse(first);
137
- }
138
- if (decoded.startsWith('{')) {
139
- return JSON.parse(decoded);
140
- }
141
- else {
142
- return decoded;
143
- }
144
- }
145
- catch (error) {
146
- utils.logger.error('[ERROR] Error processing stream event: ', error, decoded);
147
- return decoded;
148
- }
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
- }
176
- static async processStreamRequest(event) {
177
- const req = await CoreUtils.processStream(event);
178
- return new oRequest(req);
179
- }
180
- static async processStreamResponse(event) {
181
- const res = await CoreUtils.processStream(event);
182
- return new oResponse({
183
- ...res.result,
184
- id: res.id, // Preserve request ID for proper request/response correlation
185
- });
186
- }
187
98
  static async toCID(data) {
188
99
  const bytes = json.encode(data);
189
100
  const hash = await sha256.digest(bytes);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-core",
3
- "version": "0.7.34",
3
+ "version": "0.7.36",
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.34",
66
+ "@olane/o-protocol": "0.7.36",
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": "f5c2e654d18505174074f2df972c1e4851eb7ea3"
73
+ "gitHead": "26de81c453581221d62335b72f19a507bd537482"
74
74
  }