@nmtjs/protocol 0.6.5 → 0.7.1

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 (62) hide show
  1. package/dist/client/events.js +29 -26
  2. package/dist/client/events.js.map +1 -1
  3. package/dist/client/format.js +1 -2
  4. package/dist/client/format.js.map +1 -1
  5. package/dist/client/index.js.map +1 -1
  6. package/dist/client/protocol.js +331 -336
  7. package/dist/client/protocol.js.map +1 -1
  8. package/dist/client/stream.js +79 -92
  9. package/dist/client/stream.js.map +1 -1
  10. package/dist/common/binary.js +20 -20
  11. package/dist/common/binary.js.map +1 -1
  12. package/dist/common/blob.js +36 -40
  13. package/dist/common/blob.js.map +1 -1
  14. package/dist/common/enums.js +44 -44
  15. package/dist/common/enums.js.map +1 -1
  16. package/dist/common/index.js.map +1 -1
  17. package/dist/common/types.js +1 -1
  18. package/dist/common/types.js.map +1 -1
  19. package/dist/server/api.js +1 -1
  20. package/dist/server/api.js.map +1 -1
  21. package/dist/server/connection.js +18 -18
  22. package/dist/server/connection.js.map +1 -1
  23. package/dist/server/constants.js +1 -1
  24. package/dist/server/constants.js.map +1 -1
  25. package/dist/server/format.js +42 -45
  26. package/dist/server/format.js.map +1 -1
  27. package/dist/server/index.js.map +1 -1
  28. package/dist/server/injectables.js +18 -18
  29. package/dist/server/injectables.js.map +1 -1
  30. package/dist/server/protocol.js +282 -296
  31. package/dist/server/protocol.js.map +1 -1
  32. package/dist/server/registry.js +2 -19
  33. package/dist/server/registry.js.map +1 -1
  34. package/dist/server/stream.js +24 -26
  35. package/dist/server/stream.js.map +1 -1
  36. package/dist/server/transport.js +6 -6
  37. package/dist/server/transport.js.map +1 -1
  38. package/dist/server/utils.js +9 -9
  39. package/dist/server/utils.js.map +1 -1
  40. package/package.json +12 -16
  41. package/{lib → src}/client/protocol.ts +4 -3
  42. package/{lib → src}/client/stream.ts +18 -26
  43. package/{lib → src}/server/connection.ts +1 -1
  44. package/{lib → src}/server/protocol.ts +18 -8
  45. package/src/server/registry.ts +3 -0
  46. package/lib/server/registry.ts +0 -24
  47. /package/{lib → src}/client/events.ts +0 -0
  48. /package/{lib → src}/client/format.ts +0 -0
  49. /package/{lib → src}/client/index.ts +0 -0
  50. /package/{lib → src}/common/binary.ts +0 -0
  51. /package/{lib → src}/common/blob.ts +0 -0
  52. /package/{lib → src}/common/enums.ts +0 -0
  53. /package/{lib → src}/common/index.ts +0 -0
  54. /package/{lib → src}/common/types.ts +0 -0
  55. /package/{lib → src}/server/api.ts +0 -0
  56. /package/{lib → src}/server/constants.ts +0 -0
  57. /package/{lib → src}/server/format.ts +0 -0
  58. /package/{lib → src}/server/index.ts +0 -0
  59. /package/{lib → src}/server/injectables.ts +0 -0
  60. /package/{lib → src}/server/stream.ts +0 -0
  61. /package/{lib → src}/server/transport.ts +0 -0
  62. /package/{lib → src}/server/utils.ts +0 -0
@@ -1,311 +1,297 @@
1
- import { createPromise, defer, throwError } from '@nmtjs/common';
2
- import { Hook, Scope } from '@nmtjs/core';
1
+ import { createPromise, defer, throwError } from "@nmtjs/common";
2
+ import { Hook, Scope } from "@nmtjs/core";
3
3
  import { concat, decodeNumber, encodeNumber } from "../common/binary.js";
4
4
  import { ErrorCode, ServerMessageType } from "../common/enums.js";
5
5
  import { Connection, ConnectionContext } from "./connection.js";
6
6
  import { ProtocolClientStream, ProtocolServerStream } from "./stream.js";
7
7
  import { getFormat } from "./utils.js";
8
8
  export class ProtocolError extends Error {
9
- code;
10
- data;
11
- constructor(code, message, data){
12
- super(message);
13
- this.code = code;
14
- this.data = data;
15
- }
16
- get message() {
17
- return `${this.code} ${super.message}`;
18
- }
19
- toString() {
20
- return `${this.code} ${this.message}`;
21
- }
22
- toJSON() {
23
- return {
24
- code: this.code,
25
- message: this.message,
26
- data: this.data
27
- };
28
- }
9
+ code;
10
+ data;
11
+ constructor(code, message, data) {
12
+ super(message);
13
+ this.code = code;
14
+ this.data = data;
15
+ }
16
+ get message() {
17
+ return `${this.code} ${super.message}`;
18
+ }
19
+ toString() {
20
+ return `${this.code} ${this.message}`;
21
+ }
22
+ toJSON() {
23
+ return {
24
+ code: this.code,
25
+ message: this.message,
26
+ data: this.data
27
+ };
28
+ }
29
29
  }
30
30
  export class ProtocolConnections {
31
- application;
32
- #collection;
33
- constructor(application){
34
- this.application = application;
35
- this.#collection = new Map();
36
- }
37
- get(connectionId) {
38
- const connection = this.#collection.get(connectionId);
39
- if (!connection) throwError('Connection not found');
40
- return connection;
41
- }
42
- async add(transport, options, params) {
43
- const connection = new Connection(options);
44
- const format = getFormat(this.application.format, params);
45
- const container = this.application.container.fork(Scope.Connection);
46
- const context = new ConnectionContext(container, format);
47
- this.#collection.set(connection.id, {
48
- connection,
49
- context,
50
- transport
51
- });
52
- await this.application.registry.hooks.call(Hook.OnConnect, {
53
- concurrent: false
54
- }, connection);
55
- return {
56
- connection,
57
- context
58
- };
59
- }
60
- async remove(connectionId) {
61
- const { connection, context } = this.get(connectionId);
62
- this.application.registry.hooks.call(Hook.OnDisconnect, {
63
- concurrent: true
64
- }, connection);
65
- this.#collection.delete(connectionId);
66
- const { calls, serverStreams, clientStreams, rpcStreams, container } = context;
67
- for (const call of calls.values()){
68
- call.abort(new Error('Connection closed'));
69
- }
70
- for (const stream of clientStreams.values()){
71
- stream.destroy(new Error('Connection closed'));
72
- }
73
- for (const stream of serverStreams.values()){
74
- stream.destroy(new Error('Connection closed'));
75
- }
76
- for (const stream of rpcStreams.values()){
77
- stream.abort(new Error('Connection closed'));
78
- }
79
- try {
80
- await container.dispose();
81
- } catch (error) {
82
- this.application.logger.error({
83
- error,
84
- connection
85
- }, 'Error during closing connection');
86
- }
87
- }
31
+ #collection = new Map();
32
+ constructor(application) {
33
+ this.application = application;
34
+ }
35
+ get(connectionId) {
36
+ const connection = this.#collection.get(connectionId);
37
+ if (!connection) throwError("Connection not found");
38
+ return connection;
39
+ }
40
+ async add(transport, options, params) {
41
+ const connection = new Connection(options);
42
+ const format = getFormat(this.application.format, params);
43
+ const container = this.application.container.fork(Scope.Connection);
44
+ const context = new ConnectionContext(container, format);
45
+ this.#collection.set(connection.id, {
46
+ connection,
47
+ context,
48
+ transport
49
+ });
50
+ await this.application.registry.hooks.call(Hook.OnConnect, { concurrent: false }, connection);
51
+ return {
52
+ connection,
53
+ context
54
+ };
55
+ }
56
+ async remove(connectionId) {
57
+ const { connection, context } = this.get(connectionId);
58
+ this.application.registry.hooks.call(Hook.OnDisconnect, { concurrent: true }, connection);
59
+ this.#collection.delete(connectionId);
60
+ const { calls, serverStreams, clientStreams, rpcStreams, container } = context;
61
+ for (const call of calls.values()) {
62
+ call.abort(new Error("Connection closed"));
63
+ }
64
+ for (const stream of clientStreams.values()) {
65
+ stream.destroy(new Error("Connection closed"));
66
+ }
67
+ for (const stream of serverStreams.values()) {
68
+ stream.destroy(new Error("Connection closed"));
69
+ }
70
+ for (const stream of rpcStreams.values()) {
71
+ stream.abort(new Error("Connection closed"));
72
+ }
73
+ try {
74
+ await container.dispose();
75
+ } catch (error) {
76
+ this.application.logger.error({
77
+ error,
78
+ connection
79
+ }, "Error during closing connection");
80
+ }
81
+ }
88
82
  }
89
83
  export class ProtocolClientStreams {
90
- connections;
91
- constructor(connections){
92
- this.connections = connections;
93
- }
94
- get(connectionId, streamId) {
95
- const { context } = this.connections.get(connectionId);
96
- const { clientStreams } = context;
97
- const stream = clientStreams.get(streamId) ?? throwError('Stream not found');
98
- return stream;
99
- }
100
- remove(connectionId, streamId) {
101
- const { context } = this.connections.get(connectionId);
102
- const { clientStreams } = context;
103
- clientStreams.get(streamId) || throwError('Stream not found');
104
- clientStreams.delete(streamId);
105
- }
106
- add(connectionId, streamId, metadata, read) {
107
- const { context } = this.connections.get(connectionId);
108
- const { clientStreams } = context;
109
- const stream = new ProtocolClientStream(streamId, metadata, {
110
- read
111
- });
112
- clientStreams.set(streamId, stream);
113
- return stream;
114
- }
115
- push(connectionId, streamId, chunk) {
116
- const stream = this.get(connectionId, streamId);
117
- stream.push(Buffer.from(chunk));
118
- }
119
- end(connectionId, streamId) {
120
- const stream = this.get(connectionId, streamId);
121
- stream.push(null);
122
- this.remove(connectionId, streamId);
123
- }
124
- abort(connectionId, streamId, error = new Error('Aborted')) {
125
- const stream = this.get(connectionId, streamId);
126
- stream.destroy(error);
127
- this.remove(connectionId, streamId);
128
- }
84
+ constructor(connections) {
85
+ this.connections = connections;
86
+ }
87
+ get(connectionId, streamId) {
88
+ const { context } = this.connections.get(connectionId);
89
+ const { clientStreams } = context;
90
+ const stream = clientStreams.get(streamId) ?? throwError("Stream not found");
91
+ return stream;
92
+ }
93
+ remove(connectionId, streamId) {
94
+ const { context } = this.connections.get(connectionId);
95
+ const { clientStreams } = context;
96
+ clientStreams.get(streamId) || throwError("Stream not found");
97
+ clientStreams.delete(streamId);
98
+ }
99
+ add(connectionId, streamId, metadata, read) {
100
+ const { context } = this.connections.get(connectionId);
101
+ const { clientStreams } = context;
102
+ const stream = new ProtocolClientStream(streamId, metadata, { read });
103
+ clientStreams.set(streamId, stream);
104
+ return stream;
105
+ }
106
+ push(connectionId, streamId, chunk) {
107
+ const stream = this.get(connectionId, streamId);
108
+ stream.push(Buffer.from(chunk));
109
+ }
110
+ end(connectionId, streamId) {
111
+ const stream = this.get(connectionId, streamId);
112
+ stream.push(null);
113
+ this.remove(connectionId, streamId);
114
+ }
115
+ abort(connectionId, streamId, error = new Error("Aborted")) {
116
+ const stream = this.get(connectionId, streamId);
117
+ stream.destroy(error);
118
+ this.remove(connectionId, streamId);
119
+ }
129
120
  }
130
121
  export class ProtocolServerStreams {
131
- connections;
132
- constructor(connections){
133
- this.connections = connections;
134
- }
135
- get(connectionId, streamId) {
136
- const { context } = this.connections.get(connectionId);
137
- const { serverStreams } = context;
138
- const stream = serverStreams.get(streamId) ?? throwError('Stream not found');
139
- return stream;
140
- }
141
- add(connectionId, streamId, blob) {
142
- const { context } = this.connections.get(connectionId);
143
- const { serverStreams } = context;
144
- const stream = new ProtocolServerStream(streamId, blob);
145
- serverStreams.set(streamId, stream);
146
- return stream;
147
- }
148
- remove(connectionId, streamId) {
149
- const { context } = this.connections.get(connectionId);
150
- const { serverStreams } = context;
151
- serverStreams.has(streamId) || throwError('Stream not found');
152
- serverStreams.delete(streamId);
153
- }
154
- pull(connectionId, streamId) {
155
- const stream = this.get(connectionId, streamId);
156
- stream.resume();
157
- }
158
- abort(connectionId, streamId, error = new Error('Aborted')) {
159
- const stream = this.get(connectionId, streamId);
160
- stream.destroy(error);
161
- this.remove(connectionId, streamId);
162
- }
122
+ constructor(connections) {
123
+ this.connections = connections;
124
+ }
125
+ get(connectionId, streamId) {
126
+ const { context } = this.connections.get(connectionId);
127
+ const { serverStreams } = context;
128
+ const stream = serverStreams.get(streamId) ?? throwError("Stream not found");
129
+ return stream;
130
+ }
131
+ add(connectionId, streamId, blob) {
132
+ const { context } = this.connections.get(connectionId);
133
+ const { serverStreams } = context;
134
+ const stream = new ProtocolServerStream(streamId, blob);
135
+ serverStreams.set(streamId, stream);
136
+ return stream;
137
+ }
138
+ remove(connectionId, streamId) {
139
+ const { context } = this.connections.get(connectionId);
140
+ const { serverStreams } = context;
141
+ serverStreams.has(streamId) || throwError("Stream not found");
142
+ serverStreams.delete(streamId);
143
+ }
144
+ pull(connectionId, streamId) {
145
+ const stream = this.get(connectionId, streamId);
146
+ stream.resume();
147
+ }
148
+ abort(connectionId, streamId, error = new Error("Aborted")) {
149
+ const stream = this.get(connectionId, streamId);
150
+ stream.destroy(error);
151
+ this.remove(connectionId, streamId);
152
+ }
163
153
  }
164
154
  export class Protocol {
165
- application;
166
- connections;
167
- clientStreams;
168
- serverStreams;
169
- constructor(application){
170
- this.application = application;
171
- this.connections = new ProtocolConnections(this.application);
172
- this.clientStreams = new ProtocolClientStreams(this.connections);
173
- this.serverStreams = new ProtocolServerStreams(this.connections);
174
- }
175
- async rpc(connectionId, rpc, params = {}) {
176
- const { connection, context, transport } = this.connections.get(connectionId);
177
- const { calls, format } = context;
178
- const { callId, namespace, procedure, payload } = rpc;
179
- const abortController = new AbortController();
180
- const signal = params.signal ? AbortSignal.any([
181
- params.signal,
182
- abortController.signal
183
- ]) : abortController.signal;
184
- const call = Object.assign(createPromise(), {
185
- abort: ()=>abortController.abort()
186
- });
187
- calls.set(callId, call);
188
- call.promise.finally(()=>calls.delete(callId));
189
- const callIdEncoded = encodeNumber(callId, 'Uint32');
190
- const container = context.container.fork(Scope.Call);
191
- try {
192
- const response = await this.application.api.call({
193
- connection,
194
- container,
195
- namespace,
196
- payload,
197
- procedure,
198
- signal
199
- });
200
- const responseEncoded = format.encoder.encodeRPC({
201
- callId,
202
- payload: response.output
203
- }, {
204
- addStream: (blob)=>{
205
- const id = context.streamId++;
206
- const stream = this.serverStreams.add(connectionId, id, blob);
207
- stream.on('data', (chunk)=>{
208
- stream.pause();
209
- transport.send(connection, ServerMessageType.ServerStreamPush, concat(encodeNumber(id, 'Uint32'), Buffer.from(chunk).buffer));
210
- });
211
- stream.on('error', (err)=>{
212
- transport.send(connection, ServerMessageType.ServerStreamAbort, encodeNumber(id, 'Uint32'));
213
- });
214
- stream.on('end', ()=>{
215
- transport.send(connection, ServerMessageType.ServerStreamEnd, encodeNumber(id, 'Uint32'));
216
- });
217
- return stream;
218
- },
219
- getStream: (id)=>{
220
- return this.clientStreams.get(connectionId, id);
221
- }
222
- });
223
- if ('subscription' in response) {
224
- throwError('Unimplemented');
225
- } else if ('iterable' in response) {
226
- transport.send(connection, ServerMessageType.RpcStreamResponse, responseEncoded);
227
- try {
228
- const ab = new AbortController();
229
- context.rpcStreams.set(callId, ab);
230
- const iterable = typeof response.iterable === 'function' ? response.iterable() : response.iterable;
231
- for await (const chunk of iterable){
232
- if (ab.signal.aborted) break;
233
- const chunkEncoded = format.encoder.encode(chunk);
234
- transport.send(connection, ServerMessageType.RpcStreamChunk, concat(callIdEncoded, chunkEncoded));
235
- }
236
- } catch (error) {
237
- this.application.logger.error(error);
238
- transport.send(connection, ServerMessageType.RpcStreamAbort, callIdEncoded);
239
- } finally{
240
- context.rpcStreams.delete(callId);
241
- response.onFinish && defer(response.onFinish);
242
- }
243
- } else {
244
- transport.send(connection, ServerMessageType.RpcResponse, responseEncoded);
245
- }
246
- } catch (error) {
247
- if (error instanceof ProtocolError === false) {
248
- this.application.logger.error({
249
- error,
250
- connection
251
- }, 'Error during RPC call');
252
- error = new ProtocolError(ErrorCode.InternalServerError, 'Internal server error');
253
- }
254
- const payload = format.encoder.encodeRPC({
255
- callId,
256
- error
257
- }, {
258
- addStream (blob) {
259
- throwError('Cannot handle stream for error response');
260
- },
261
- getStream (id) {
262
- throwError('Cannot handle stream for error response');
263
- }
264
- });
265
- transport.send(connection, ServerMessageType.RpcResponse, payload);
266
- } finally{
267
- container.dispose().catch((error)=>{
268
- this.application.logger.error({
269
- error,
270
- connection
271
- }, "Error during disposing connection's container");
272
- });
273
- }
274
- }
275
- async rpcRaw(connectionId, buffer, params = {}) {
276
- const { connection, context, transport } = this.connections.get(connectionId);
277
- const { format } = context;
278
- const rpc = format.decoder.decodeRPC(buffer, {
279
- addStream: (id, metadata)=>{
280
- return this.clientStreams.add(connectionId, id, metadata, (size)=>{
281
- transport.send(connection, ServerMessageType.ClientStreamPull, concat(encodeNumber(id, 'Uint32'), encodeNumber(size, 'Uint32')));
282
- });
283
- },
284
- getStream: (id)=>{
285
- return this.serverStreams.get(connectionId, id);
286
- }
287
- });
288
- return await this.rpc(connectionId, rpc, params);
289
- }
290
- rpcAbort(connectionId, callId) {
291
- const { context } = this.connections.get(connectionId);
292
- const call = context.calls.get(callId) ?? throwError('Call not found');
293
- call.abort();
294
- }
295
- rpcAbortRaw(connectionId, buffer) {
296
- const callId = decodeNumber(buffer, 'Uint32');
297
- return this.rpcAbort(connectionId, callId);
298
- }
299
- rpcStreamAbort(connectionId, callId) {
300
- const { context } = this.connections.get(connectionId);
301
- const ab = context.rpcStreams.get(callId) ?? throwError('Call stream not found');
302
- ab.abort();
303
- }
304
- rpcStreamAbortRaw(connectionId, buffer) {
305
- const callId = decodeNumber(buffer, 'Uint32');
306
- return this.rpcStreamAbort(connectionId, callId);
307
- }
308
- notify(connectionId, event, payload) {
309
- throw Error('Unimplemented');
310
- }
155
+ connections;
156
+ clientStreams;
157
+ serverStreams;
158
+ constructor(application) {
159
+ this.application = application;
160
+ this.connections = new ProtocolConnections(this.application);
161
+ this.clientStreams = new ProtocolClientStreams(this.connections);
162
+ this.serverStreams = new ProtocolServerStreams(this.connections);
163
+ }
164
+ async rpc(connectionId, rpc, params = {}) {
165
+ const { connection, context, transport } = this.connections.get(connectionId);
166
+ const { calls, format } = context;
167
+ const { callId, namespace, procedure, payload } = rpc;
168
+ const abortController = new AbortController();
169
+ const signal = params.signal ? AbortSignal.any([params.signal, abortController.signal]) : abortController.signal;
170
+ const call = Object.assign(createPromise(), { abort: () => abortController.abort() });
171
+ calls.set(callId, call);
172
+ call.promise.finally(() => calls.delete(callId));
173
+ const callIdEncoded = encodeNumber(callId, "Uint32");
174
+ const container = context.container.fork(Scope.Call);
175
+ try {
176
+ const response = await this.application.api.call({
177
+ connection,
178
+ container,
179
+ namespace,
180
+ payload,
181
+ procedure,
182
+ signal
183
+ });
184
+ const responseEncoded = format.encoder.encodeRPC({
185
+ callId,
186
+ payload: response.output
187
+ }, {
188
+ addStream: (blob) => {
189
+ const id = context.streamId++;
190
+ const stream = this.serverStreams.add(connectionId, id, blob);
191
+ stream.on("data", (chunk) => {
192
+ stream.pause();
193
+ const buf = Buffer.from(chunk);
194
+ transport.send(connection, ServerMessageType.ServerStreamPush, concat(encodeNumber(id, "Uint32"), buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)));
195
+ });
196
+ stream.on("error", (err) => {
197
+ transport.send(connection, ServerMessageType.ServerStreamAbort, encodeNumber(id, "Uint32"));
198
+ });
199
+ stream.on("end", () => {
200
+ transport.send(connection, ServerMessageType.ServerStreamEnd, encodeNumber(id, "Uint32"));
201
+ });
202
+ return stream;
203
+ },
204
+ getStream: (id) => {
205
+ return this.clientStreams.get(connectionId, id);
206
+ }
207
+ });
208
+ if ("subscription" in response) {
209
+ throwError("Unimplemented");
210
+ } else if ("iterable" in response) {
211
+ transport.send(connection, ServerMessageType.RpcStreamResponse, responseEncoded);
212
+ try {
213
+ const ab = new AbortController();
214
+ context.rpcStreams.set(callId, ab);
215
+ const iterable = typeof response.iterable === "function" ? response.iterable() : response.iterable;
216
+ for await (const chunk of iterable) {
217
+ if (ab.signal.aborted) break;
218
+ const chunkEncoded = format.encoder.encode(chunk);
219
+ transport.send(connection, ServerMessageType.RpcStreamChunk, concat(callIdEncoded, chunkEncoded));
220
+ }
221
+ } catch (error) {
222
+ this.application.logger.error(error);
223
+ transport.send(connection, ServerMessageType.RpcStreamAbort, callIdEncoded);
224
+ } finally {
225
+ context.rpcStreams.delete(callId);
226
+ response.onFinish && defer(response.onFinish);
227
+ }
228
+ } else {
229
+ transport.send(connection, ServerMessageType.RpcResponse, responseEncoded);
230
+ }
231
+ } catch (error) {
232
+ if (error instanceof ProtocolError === false) {
233
+ this.application.logger.error({
234
+ error,
235
+ connection
236
+ }, "Error during RPC call");
237
+ error = new ProtocolError(ErrorCode.InternalServerError, "Internal server error");
238
+ }
239
+ const payload = format.encoder.encodeRPC({
240
+ callId,
241
+ error
242
+ }, {
243
+ addStream(blob) {
244
+ throwError("Cannot handle stream for error response");
245
+ },
246
+ getStream(id) {
247
+ throwError("Cannot handle stream for error response");
248
+ }
249
+ });
250
+ transport.send(connection, ServerMessageType.RpcResponse, payload);
251
+ } finally {
252
+ container.dispose().catch((error) => {
253
+ this.application.logger.error({
254
+ error,
255
+ connection
256
+ }, "Error during disposing connection's container");
257
+ });
258
+ }
259
+ }
260
+ async rpcRaw(connectionId, buffer, params = {}) {
261
+ const { connection, context, transport } = this.connections.get(connectionId);
262
+ const { format } = context;
263
+ const rpc = format.decoder.decodeRPC(buffer, {
264
+ addStream: (id, metadata) => {
265
+ const stream = this.clientStreams.add(connectionId, id, metadata, (size) => {
266
+ transport.send(connection, ServerMessageType.ClientStreamPull, concat(encodeNumber(id, "Uint32"), encodeNumber(size, "Uint32")));
267
+ });
268
+ return stream;
269
+ },
270
+ getStream: (id) => {
271
+ return this.serverStreams.get(connectionId, id);
272
+ }
273
+ });
274
+ return await this.rpc(connectionId, rpc, params);
275
+ }
276
+ rpcAbort(connectionId, callId) {
277
+ const { context } = this.connections.get(connectionId);
278
+ const call = context.calls.get(callId) ?? throwError("Call not found");
279
+ call.abort();
280
+ }
281
+ rpcAbortRaw(connectionId, buffer) {
282
+ const callId = decodeNumber(buffer, "Uint32");
283
+ return this.rpcAbort(connectionId, callId);
284
+ }
285
+ rpcStreamAbort(connectionId, callId) {
286
+ const { context } = this.connections.get(connectionId);
287
+ const ab = context.rpcStreams.get(callId) ?? throwError("Call stream not found");
288
+ ab.abort();
289
+ }
290
+ rpcStreamAbortRaw(connectionId, buffer) {
291
+ const callId = decodeNumber(buffer, "Uint32");
292
+ return this.rpcStreamAbort(connectionId, callId);
293
+ }
294
+ notify(connectionId, event, payload) {
295
+ throw Error("Unimplemented");
296
+ }
311
297
  }