@nmtjs/protocol 0.13.1 → 0.14.0

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.
@@ -1,9 +1,9 @@
1
- import { type InteractivePromise, type OneOf } from '@nmtjs/common';
1
+ import type { InteractivePromise, OneOf } from '@nmtjs/common';
2
2
  import type { ProtocolBlobMetadata } from '../common/blob.ts';
3
+ import type { BaseProtocolError, ProtocolRPCResponse } from '../common/types.ts';
4
+ import type { BaseClientFormat } from './format.ts';
3
5
  import { ClientMessageType, ServerMessageType } from '../common/enums.ts';
4
- import type { BaseProtocolError, ProtocolRPC, ProtocolRPCResponse } from '../common/types.ts';
5
6
  import { EventEmitter } from './events.ts';
6
- import type { BaseClientFormat } from './format.ts';
7
7
  import { ProtocolClientBlobStream, ProtocolServerBlobStream, ProtocolServerStream } from './stream.ts';
8
8
  export declare class ProtocolError extends Error implements BaseProtocolError {
9
9
  code: string;
@@ -55,16 +55,17 @@ export declare abstract class ProtocolTransport extends EventEmitter<ProtocolTra
55
55
  status: ProtocolTransportStatus;
56
56
  abstract connect(auth: any, transformer: ProtocolBaseTransformer): Promise<void>;
57
57
  abstract disconnect(): Promise<void>;
58
- abstract call(namespace: string, procedure: string, payload: any, options: ProtocolBaseClientCallOptions, transformer: ProtocolBaseTransformer): Promise<ProtocolClientCall>;
58
+ abstract call(procedure: string, payload: any, options: ProtocolBaseClientCallOptions, transformer: ProtocolBaseTransformer): Promise<ProtocolClientCall>;
59
59
  abstract send(messageType: ClientMessageType, buffer: ArrayBuffer, metadata: ProtocolSendMetadata): Promise<void>;
60
60
  }
61
61
  export declare class ProtocolBaseTransformer {
62
- encodeRPC(namespace: string, procedure: string, payload: any): any;
63
- decodeRPC(namespace: string, procedure: string, payload: any): any;
64
- decodeRPCChunk(namespace: string, procedure: string, payload: any): any;
65
- decodeEvent(namespace: string, event: string, payload: any): any;
62
+ encodeRPC(_procedure: string, payload: any): any;
63
+ decodeRPC(_procedure: string, payload: any): any;
64
+ decodeRPCChunk(_procedure: string, payload: any): any;
65
+ decodeEvent(_event: string, payload: any): any;
66
66
  }
67
- export type ProtocolClientCall = InteractivePromise<any> & Pick<ProtocolRPC, 'namespace' | 'procedure'> & {
67
+ export type ProtocolClientCall = InteractivePromise<any> & {
68
+ procedure: string;
68
69
  signal: AbortSignal;
69
70
  };
70
71
  export type ProtocolBaseClientOptions = {
@@ -104,15 +105,13 @@ export declare class BaseProtocol<T extends Record<string, Record<string, any>>
104
105
  ]>, transformer: ProtocolBaseTransformer): void;
105
106
  handleRpcResponse({ callId, error, result, streams }: ProtocolRPCResponse, transformer: ProtocolBaseTransformer, stream?: ProtocolServerStream): ProtocolClientCall;
106
107
  handleRpcStreamResponse(response: ProtocolRPCResponse, stream: ProtocolServerStream, transformer: ProtocolBaseTransformer): ProtocolClientCall;
107
- createCall(namespace: string, procedure: string, options: ProtocolBaseClientCallOptions): InteractivePromise<unknown> & {
108
- namespace: string;
108
+ createCall(procedure: string, options: ProtocolBaseClientCallOptions): InteractivePromise<unknown> & {
109
109
  procedure: string;
110
110
  signal: AbortSignal;
111
111
  };
112
- createRpc(namespace: string, procedure: string, payload: any, options: ProtocolBaseClientCallOptions, transformer: ProtocolBaseTransformer): {
112
+ createRpc(procedure: string, payload: any, options: ProtocolBaseClientCallOptions, transformer: ProtocolBaseTransformer): {
113
113
  callId: number;
114
114
  call: InteractivePromise<unknown> & {
115
- namespace: string;
116
115
  procedure: string;
117
116
  signal: AbortSignal;
118
117
  };
@@ -130,20 +129,20 @@ export declare class BaseProtocol<T extends Record<string, Record<string, any>>
130
129
  removeServerStream(streamId: number): void;
131
130
  pushServerStream(streamId: number, chunk: ArrayBuffer): Promise<void>;
132
131
  endServerStream(streamId: number): void;
133
- abortServerStream(streamId: number, error?: Error): void;
134
- emitEvent(namespace: string, event: string, payload: string, transformer: ProtocolBaseTransformer): void;
132
+ abortServerStream(streamId: number, _error?: Error): void;
133
+ emitEvent(event: string, payload: string, transformer: ProtocolBaseTransformer): void;
135
134
  }
136
135
  export declare class Protocol<T extends Record<string, Record<string, any>> = Record<string, Record<string, any>>> extends BaseProtocol<T> {
137
136
  handleServerMessage(buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
138
- protected [ServerMessageType.Event](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
137
+ protected [ServerMessageType.Event](buffer: ArrayBuffer, _transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
139
138
  protected [ServerMessageType.RpcResponse](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
140
139
  protected [ServerMessageType.RpcStreamResponse](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
141
- protected [ServerMessageType.RpcStreamChunk](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
142
- protected [ServerMessageType.RpcStreamEnd](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
143
- protected [ServerMessageType.RpcStreamAbort](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
144
- protected [ServerMessageType.ServerStreamPush](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
145
- protected [ServerMessageType.ServerStreamEnd](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
146
- protected [ServerMessageType.ServerStreamAbort](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
147
- protected [ServerMessageType.ClientStreamPull](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
148
- protected [ServerMessageType.ClientStreamAbort](buffer: ArrayBuffer, transport: ProtocolTransport, transformer: ProtocolBaseTransformer): void;
140
+ protected [ServerMessageType.RpcStreamChunk](buffer: ArrayBuffer, _transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
141
+ protected [ServerMessageType.RpcStreamEnd](buffer: ArrayBuffer, _transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
142
+ protected [ServerMessageType.RpcStreamAbort](buffer: ArrayBuffer, _transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
143
+ protected [ServerMessageType.ServerStreamPush](buffer: ArrayBuffer, transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
144
+ protected [ServerMessageType.ServerStreamEnd](buffer: ArrayBuffer, _transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
145
+ protected [ServerMessageType.ServerStreamAbort](buffer: ArrayBuffer, _transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
146
+ protected [ServerMessageType.ClientStreamPull](buffer: ArrayBuffer, transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
147
+ protected [ServerMessageType.ClientStreamAbort](buffer: ArrayBuffer, _transport: ProtocolTransport, _transformer: ProtocolBaseTransformer): void;
149
148
  }
@@ -1,4 +1,4 @@
1
- import { createPromise, } from '@nmtjs/common';
1
+ import { createPromise } from '@nmtjs/common';
2
2
  import { concat, decodeNumber, encodeNumber } from "../common/binary.js";
3
3
  import { ClientMessageType, ErrorCode, ServerMessageType, } from "../common/enums.js";
4
4
  import { EventEmitter } from "./events.js";
@@ -18,11 +18,7 @@ export class ProtocolError extends Error {
18
18
  return `${this.code} ${this.message}`;
19
19
  }
20
20
  toJSON() {
21
- return {
22
- code: this.code,
23
- message: this.message,
24
- data: this.data,
25
- };
21
+ return { code: this.code, message: this.message, data: this.data };
26
22
  }
27
23
  }
28
24
  export class ProtocolClientStreams {
@@ -116,16 +112,16 @@ export class ProtocolTransport extends EventEmitter {
116
112
  status = ProtocolTransportStatus.DISCONNECTED;
117
113
  }
118
114
  export class ProtocolBaseTransformer {
119
- encodeRPC(namespace, procedure, payload) {
115
+ encodeRPC(_procedure, payload) {
120
116
  return payload;
121
117
  }
122
- decodeRPC(namespace, procedure, payload) {
118
+ decodeRPC(_procedure, payload) {
123
119
  return payload;
124
120
  }
125
- decodeRPCChunk(namespace, procedure, payload) {
121
+ decodeRPCChunk(_procedure, payload) {
126
122
  return payload;
127
123
  }
128
- decodeEvent(namespace, event, payload) {
124
+ decodeEvent(_event, payload) {
129
125
  return payload;
130
126
  }
131
127
  }
@@ -150,7 +146,7 @@ export class BaseProtocol extends EventEmitter {
150
146
  }
151
147
  else {
152
148
  try {
153
- const transformed = transformer.decodeRPC(call.namespace, call.procedure, response.result);
149
+ const transformed = transformer.decodeRPC(call.procedure, response.result);
154
150
  if (response.stream)
155
151
  call.resolve({ result: transformed, stream: response.stream });
156
152
  else
@@ -178,31 +174,22 @@ export class BaseProtocol extends EventEmitter {
178
174
  this.rpcStreams.add(response.callId, stream);
179
175
  return call;
180
176
  }
181
- createCall(namespace, procedure, options) {
177
+ createCall(procedure, options) {
182
178
  const timeoutSignal = AbortSignal.timeout(options.timeout);
183
179
  const signal = options.signal
184
180
  ? AbortSignal.any([options.signal, timeoutSignal])
185
181
  : timeoutSignal;
186
- const call = Object.assign(createPromise(), {
187
- namespace,
188
- procedure,
189
- signal,
190
- });
182
+ const call = Object.assign(createPromise(), { procedure, signal });
191
183
  timeoutSignal.addEventListener('abort', () => {
192
184
  const error = new ProtocolError(ErrorCode.RequestTimeout, 'Request timeout');
193
185
  call.reject(error);
194
186
  }, { once: true });
195
187
  return call;
196
188
  }
197
- createRpc(namespace, procedure, payload, options, transformer) {
189
+ createRpc(procedure, payload, options, transformer) {
198
190
  const callId = ++this.callId;
199
- const call = this.createCall(namespace, procedure, options);
200
- const { buffer, streams } = this.format.encodeRPC({
201
- callId,
202
- namespace,
203
- procedure,
204
- payload: transformer.encodeRPC(namespace, procedure, payload),
205
- }, {
191
+ const call = this.createCall(procedure, options);
192
+ const { buffer, streams } = this.format.encodeRPC({ callId, procedure, payload: transformer.encodeRPC(procedure, payload) }, {
206
193
  addStream: (blob) => {
207
194
  const streamId = ++this.streamId;
208
195
  return this.clientStreams.add(blob.source, streamId, blob.metadata);
@@ -248,12 +235,12 @@ export class BaseProtocol extends EventEmitter {
248
235
  endServerStream(streamId) {
249
236
  this.serverStreams.end(streamId);
250
237
  }
251
- abortServerStream(streamId, error) {
238
+ abortServerStream(streamId, _error) {
252
239
  this.serverStreams.abort(streamId);
253
240
  }
254
- emitEvent(namespace, event, payload, transformer) {
255
- const transformed = transformer.decodeEvent(namespace, event, payload);
256
- this.emit(`${namespace}/${event}`,
241
+ emitEvent(event, payload, transformer) {
242
+ const transformed = transformer.decodeEvent(event, payload);
243
+ this.emit(event,
257
244
  //@ts-expect-error
258
245
  transformed);
259
246
  }
@@ -272,9 +259,9 @@ export class Protocol extends BaseProtocol {
272
259
  }
273
260
  }
274
261
  }
275
- [ServerMessageType.Event](buffer, transport, transformer) {
276
- const [namespace, event, payload] = this.format.decode(buffer);
277
- this.emitEvent(namespace, event, payload, transformer);
262
+ [ServerMessageType.Event](buffer, _transport, transformer) {
263
+ const [event, payload] = this.format.decode(buffer);
264
+ this.emitEvent(event, payload, transformer);
278
265
  }
279
266
  [ServerMessageType.RpcResponse](buffer, transport, transformer) {
280
267
  const response = this.format.decodeRPC(buffer, {
@@ -306,41 +293,41 @@ export class Protocol extends BaseProtocol {
306
293
  });
307
294
  const stream = new ProtocolServerStream({
308
295
  transform: (chunk, controller) => {
309
- const transformed = transformer.decodeRPCChunk(call.namespace, call.procedure, chunk);
296
+ const transformed = transformer.decodeRPCChunk(call.procedure, chunk);
310
297
  controller.enqueue(transformed);
311
298
  },
312
299
  });
313
300
  const call = this.handleRpcStreamResponse(response, stream, transformer);
314
301
  }
315
- [ServerMessageType.RpcStreamChunk](buffer, transport, transformer) {
302
+ [ServerMessageType.RpcStreamChunk](buffer, _transport, _transformer) {
316
303
  const callId = decodeNumber(buffer, 'Uint32');
317
304
  const chunk = buffer.slice(Uint32Array.BYTES_PER_ELEMENT);
318
305
  const payload = this.format.decode(chunk);
319
306
  this.pushRpcStream(callId, payload);
320
307
  }
321
- [ServerMessageType.RpcStreamEnd](buffer, transport, transformer) {
308
+ [ServerMessageType.RpcStreamEnd](buffer, _transport, _transformer) {
322
309
  const callId = decodeNumber(buffer, 'Uint32');
323
310
  this.endRpcStream(callId);
324
311
  }
325
- [ServerMessageType.RpcStreamAbort](buffer, transport, transformer) {
312
+ [ServerMessageType.RpcStreamAbort](buffer, _transport, _transformer) {
326
313
  const callId = decodeNumber(buffer, 'Uint32');
327
314
  this.abortRpcStream(callId);
328
315
  }
329
- [ServerMessageType.ServerStreamPush](buffer, transport, transformer) {
316
+ [ServerMessageType.ServerStreamPush](buffer, transport, _transformer) {
330
317
  const streamId = decodeNumber(buffer, 'Uint32');
331
318
  const chunk = buffer.slice(Uint32Array.BYTES_PER_ELEMENT);
332
319
  this.pushServerStream(streamId, chunk);
333
320
  transport.send(ClientMessageType.ServerStreamPull, encodeNumber(streamId, 'Uint32'), { streamId });
334
321
  }
335
- [ServerMessageType.ServerStreamEnd](buffer, transport, transformer) {
322
+ [ServerMessageType.ServerStreamEnd](buffer, _transport, _transformer) {
336
323
  const streamId = decodeNumber(buffer, 'Uint32');
337
324
  this.endServerStream(streamId);
338
325
  }
339
- [ServerMessageType.ServerStreamAbort](buffer, transport, transformer) {
326
+ [ServerMessageType.ServerStreamAbort](buffer, _transport, _transformer) {
340
327
  const streamId = decodeNumber(buffer, 'Uint32');
341
328
  this.abortServerStream(streamId);
342
329
  }
343
- [ServerMessageType.ClientStreamPull](buffer, transport, transformer) {
330
+ [ServerMessageType.ClientStreamPull](buffer, transport, _transformer) {
344
331
  const streamId = decodeNumber(buffer, 'Uint32');
345
332
  const size = decodeNumber(buffer, 'Uint32', Uint32Array.BYTES_PER_ELEMENT);
346
333
  this.pullClientStream(streamId, size).then((chunk) => {
@@ -355,7 +342,7 @@ export class Protocol extends BaseProtocol {
355
342
  transport.send(ClientMessageType.ClientStreamAbort, encodeNumber(streamId, 'Uint32'), { streamId });
356
343
  });
357
344
  }
358
- [ServerMessageType.ClientStreamAbort](buffer, transport, transformer) {
345
+ [ServerMessageType.ClientStreamAbort](buffer, _transport, _transformer) {
359
346
  const streamId = decodeNumber(buffer, 'Uint32');
360
347
  this.abortClientStream(streamId);
361
348
  }
@@ -7,11 +7,7 @@ export class ProtocolBlob {
7
7
  if (typeof size !== 'undefined' && size <= 0)
8
8
  throw new Error('Blob size is invalid');
9
9
  this.source = source;
10
- this.metadata = {
11
- size,
12
- type,
13
- filename,
14
- };
10
+ this.metadata = { size, type, filename };
15
11
  }
16
12
  static from(source, metadata = {}) {
17
13
  let _source;
@@ -8,7 +8,6 @@ export interface BaseProtocolError {
8
8
  }
9
9
  export type ProtocolRPC = {
10
10
  callId: number;
11
- namespace: string;
12
11
  procedure: string;
13
12
  payload: any;
14
13
  };
@@ -4,12 +4,11 @@ import type { Connection } from './connection.ts';
4
4
  import { kIterableResponse } from './constants.ts';
5
5
  export type ProtocolApiCallOptions = {
6
6
  connection: Connection;
7
- namespace: string;
8
7
  procedure: string;
9
8
  container: Container;
10
9
  payload: any;
11
10
  signal: AbortSignal;
12
- metadata?: (metadata: MetadataStore) => void;
11
+ validateMetadata?: (metadata: MetadataStore) => void;
13
12
  };
14
13
  export type ProtocolAnyIterable<T> = ((signal: AbortSignal) => Async<AsyncIterable<T>>) | AsyncIterable<T>;
15
14
  export interface ProtocolApiCallBaseResult<T = unknown> {
@@ -3,10 +3,5 @@ export function isIterableResult(value) {
3
3
  return value && value[kIterableResponse] === true;
4
4
  }
5
5
  export function createStreamResponse(iterable, output = undefined, onFinish) {
6
- return {
7
- [kIterableResponse]: true,
8
- iterable,
9
- output,
10
- onFinish,
11
- };
6
+ return { [kIterableResponse]: true, iterable, output, onFinish };
12
7
  }
@@ -1,5 +1,5 @@
1
1
  import type { OneOf } from '@nmtjs/common';
2
- import { type Pattern } from '@nmtjs/core';
2
+ import type { Pattern } from '@nmtjs/core';
3
3
  import type { DecodeRPCContext, EncodeRPCContext, ProtocolRPC, ProtocolRPCResponse } from '../common/types.ts';
4
4
  import type { ProtocolClientStream, ProtocolServerStream } from './stream.ts';
5
5
  export interface BaseServerDecoder {
@@ -1,14 +1,15 @@
1
- import { type Callback } from '@nmtjs/common';
2
- import { type AnyInjectable, type Container, type Logger } from '@nmtjs/core';
1
+ import type { Callback } from '@nmtjs/common';
2
+ import type { AnyInjectable, Container, Logger } from '@nmtjs/core';
3
3
  import type { ProtocolBlob, ProtocolBlobMetadata } from '../common/blob.ts';
4
4
  import type { ProtocolRPC } from '../common/types.ts';
5
- import { type ProtocolApi, type ProtocolApiCallOptions } from './api.ts';
6
- import { Connection, ConnectionContext, type ConnectionOptions } from './connection.ts';
5
+ import type { ProtocolApi, ProtocolApiCallOptions } from './api.ts';
6
+ import type { ConnectionOptions } from './connection.ts';
7
7
  import type { Format } from './format.ts';
8
8
  import type { ProtocolRegistry } from './registry.ts';
9
- import { ProtocolClientStream, ProtocolServerStream } from './stream.ts';
10
9
  import type { Transport } from './transport.ts';
11
- import { type ResolveFormatParams } from './utils.ts';
10
+ import type { ResolveFormatParams } from './utils.ts';
11
+ import { Connection, ConnectionContext } from './connection.ts';
12
+ import { ProtocolClientStream, ProtocolServerStream } from './stream.ts';
12
13
  export declare class ProtocolError extends Error {
13
14
  code: string;
14
15
  data?: any;
@@ -67,7 +68,7 @@ export declare class ProtocolServerStreams {
67
68
  export type ProtocolRPCOptions = {
68
69
  signal?: AbortSignal;
69
70
  provides?: [AnyInjectable, any][];
70
- metadata?: ProtocolApiCallOptions['metadata'];
71
+ validateMetadata?: ProtocolApiCallOptions['validateMetadata'];
71
72
  };
72
73
  export declare class Protocol {
73
74
  #private;
@@ -92,7 +93,7 @@ export declare class Protocol {
92
93
  rpcAbortRaw(connectionId: string, buffer: ArrayBuffer): void;
93
94
  rpcStreamAbort(connectionId: string, callId: number): void;
94
95
  rpcStreamAbortRaw(connectionId: string, buffer: ArrayBuffer): void;
95
- notify(connectionId: string, event: any, payload: any): void;
96
+ notify(): void;
96
97
  addConnection(transport: ProtocolConnectionTransport, options: ConnectionOptions, params: ResolveFormatParams): Promise<{
97
98
  connection: Connection<unknown>;
98
99
  context: ConnectionContext;
@@ -1,9 +1,9 @@
1
1
  import { defer, isAbortError, throwError } from '@nmtjs/common';
2
- import { Hook, Scope, } from '@nmtjs/core';
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
- import { isIterableResult, } from "./api.js";
6
- import { Connection, ConnectionContext, } from "./connection.js";
5
+ import { isIterableResult } from "./api.js";
6
+ import { Connection, ConnectionContext } from "./connection.js";
7
7
  import { ProtocolInjectables } from "./injectables.js";
8
8
  import { ProtocolClientStream, ProtocolServerStream } from "./stream.js";
9
9
  import { getFormat } from "./utils.js";
@@ -22,11 +22,7 @@ export class ProtocolError extends Error {
22
22
  return `${this.code} ${this.message}`;
23
23
  }
24
24
  toJSON() {
25
- return {
26
- code: this.code,
27
- message: this.message,
28
- data: this.data,
29
- };
25
+ return { code: this.code, message: this.message, data: this.data };
30
26
  }
31
27
  }
32
28
  export class ProtocolConnections {
@@ -192,7 +188,7 @@ export class Protocol {
192
188
  async rpc(connectionId, rpc, params = {}) {
193
189
  const { connection, context, transport } = this.#connections.get(connectionId);
194
190
  const { rpcs, format } = context;
195
- const { callId, namespace, procedure, payload } = rpc;
191
+ const { callId, procedure, payload } = rpc;
196
192
  const abortController = new AbortController();
197
193
  const signal = params.signal
198
194
  ? AbortSignal.any([params.signal, abortController.signal])
@@ -209,16 +205,12 @@ export class Protocol {
209
205
  const response = await this.call({
210
206
  connection,
211
207
  container,
212
- namespace,
213
208
  payload,
214
209
  procedure,
215
210
  signal,
216
- metadata: params.metadata,
211
+ validateMetadata: params.validateMetadata,
217
212
  });
218
- const responseEncoded = format.encoder.encodeRPC({
219
- callId,
220
- result: response.output,
221
- }, {
213
+ const responseEncoded = format.encoder.encodeRPC({ callId, result: response.output }, {
222
214
  addStream: (blob) => {
223
215
  const streamId = context.streamId++;
224
216
  const stream = this.#serverStreams.add(connectionId, streamId, blob);
@@ -227,7 +219,7 @@ export class Protocol {
227
219
  const buf = Buffer.from(chunk);
228
220
  transport.send(connection, ServerMessageType.ServerStreamPush, concat(encodeNumber(streamId, 'Uint32'), buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)), { callId, streamId });
229
221
  });
230
- stream.on('error', (err) => {
222
+ stream.on('error', () => {
231
223
  transport.send(connection, ServerMessageType.ServerStreamAbort, encodeNumber(streamId, 'Uint32'), { callId, streamId });
232
224
  });
233
225
  stream.on('end', () => {
@@ -277,10 +269,10 @@ export class Protocol {
277
269
  }
278
270
  catch (error) {
279
271
  const payload = format.encoder.encodeRPC({ callId, error }, {
280
- addStream(blob) {
272
+ addStream() {
281
273
  throwError('Cannot handle stream for error response');
282
274
  },
283
- getStream(id) {
275
+ getStream() {
284
276
  throwError('Cannot handle stream for error response');
285
277
  },
286
278
  });
@@ -329,7 +321,7 @@ export class Protocol {
329
321
  const callId = decodeNumber(buffer, 'Uint32');
330
322
  return this.rpcStreamAbort(connectionId, callId);
331
323
  }
332
- notify(connectionId, event, payload) {
324
+ notify() {
333
325
  throw Error('Unimplemented');
334
326
  }
335
327
  addConnection(transport, options, params) {
@@ -1,4 +1,5 @@
1
- import { PassThrough, type ReadableOptions } from 'node:stream';
1
+ import type { ReadableOptions } from 'node:stream';
2
+ import { PassThrough } from 'node:stream';
2
3
  import type { ProtocolBlob, ProtocolBlobMetadata } from '../common/blob.ts';
3
4
  export declare class ProtocolClientStream extends PassThrough {
4
5
  readonly id: number;
@@ -1,11 +1,11 @@
1
1
  import type { BasePlugin, PluginContext } from '@nmtjs/core';
2
2
  import type { ServerMessageType } from '../common/enums.ts';
3
3
  import type { Connection } from './connection.ts';
4
- import { kTransportPlugin } from './constants.ts';
5
4
  import type { Format } from './format.ts';
6
5
  import type { Protocol } from './protocol.ts';
7
6
  import type { ProtocolRegistry } from './registry.ts';
8
7
  import type { ProtocolSendMetadata } from './types.ts';
8
+ import { kTransportPlugin } from './constants.ts';
9
9
  export interface Transport<T = unknown> {
10
10
  start: () => Promise<void>;
11
11
  stop: () => Promise<void>;
@@ -11,8 +11,5 @@ export const getFormat = (format, { acceptType, contentType }) => {
11
11
  const decoder = acceptType ? format.supportsDecoder(acceptType) : undefined;
12
12
  if (!decoder)
13
13
  throw new UnsupportedAcceptTypeError('Unsupported Accept-Type');
14
- return {
15
- encoder,
16
- decoder,
17
- };
14
+ return { encoder, decoder };
18
15
  };
package/package.json CHANGED
@@ -19,21 +19,21 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@nmtjs/core": "0.13.1",
23
- "@nmtjs/type": "0.13.1",
24
- "@nmtjs/common": "0.13.1"
22
+ "@nmtjs/core": "0.14.0",
23
+ "@nmtjs/common": "0.14.0",
24
+ "@nmtjs/type": "0.14.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "@nmtjs/common": "0.13.1",
28
- "@nmtjs/core": "0.13.1",
29
- "@nmtjs/type": "0.13.1"
27
+ "@nmtjs/common": "0.14.0",
28
+ "@nmtjs/type": "0.14.0",
29
+ "@nmtjs/core": "0.14.0"
30
30
  },
31
31
  "files": [
32
32
  "dist",
33
33
  "LICENSE.md",
34
34
  "README.md"
35
35
  ],
36
- "version": "0.13.1",
36
+ "version": "0.14.0",
37
37
  "scripts": {
38
38
  "build": "tsc",
39
39
  "type-check": "tsc --noEmit"