@nmtjs/http-client 0.13.0 → 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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { type ClientMessageType } from '@nmtjs/protocol';
2
- import { type BaseProtocol, EventEmitter, type ProtocolBaseClientCallOptions, type ProtocolBaseTransformer, type ProtocolClientCall, type ProtocolSendMetadata, type ProtocolTransport, type ProtocolTransportEventMap, ProtocolTransportStatus } from '@nmtjs/protocol/client';
1
+ import type { ClientMessageType } from '@nmtjs/protocol';
2
+ import type { BaseProtocol, ProtocolBaseClientCallOptions, ProtocolBaseTransformer, ProtocolClientCall, ProtocolSendMetadata, ProtocolTransport, ProtocolTransportEventMap } from '@nmtjs/protocol/client';
3
+ import { EventEmitter, ProtocolTransportStatus } from '@nmtjs/protocol/client';
3
4
  export type HttpClientTransportOptions = {
4
5
  /**
5
6
  * The origin of the server
@@ -14,8 +15,8 @@ export declare class HttpClientTransport extends EventEmitter<ProtocolTransportE
14
15
  private readonly options;
15
16
  status: ProtocolTransportStatus;
16
17
  constructor(protocol: BaseProtocol, options: HttpClientTransportOptions);
17
- call(namespace: string, procedure: string, payload: any, options: ProtocolBaseClientCallOptions, transformer: ProtocolBaseTransformer): Promise<ProtocolClientCall>;
18
+ call(procedure: string, payload: any, options: ProtocolBaseClientCallOptions, transformer: ProtocolBaseTransformer): Promise<ProtocolClientCall>;
18
19
  connect(auth: any): Promise<void>;
19
20
  disconnect(): Promise<void>;
20
- send(messageType: ClientMessageType, buffer: ArrayBuffer, metadata: ProtocolSendMetadata): Promise<void>;
21
+ send(_messageType: ClientMessageType, _buffer: ArrayBuffer, _metadata: ProtocolSendMetadata): Promise<void>;
21
22
  }
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ClientError } from '@nmtjs/client';
2
- import { ErrorCode, ProtocolBlob, } from '@nmtjs/protocol';
2
+ import { ErrorCode, ProtocolBlob } from '@nmtjs/protocol';
3
3
  import { EventEmitter, ProtocolServerBlobStream, ProtocolTransportStatus, } from '@nmtjs/protocol/client';
4
4
  export class HttpClientTransport extends EventEmitter {
5
5
  protocol;
@@ -11,8 +11,8 @@ export class HttpClientTransport extends EventEmitter {
11
11
  this.protocol = protocol;
12
12
  this.options = options;
13
13
  }
14
- async call(namespace, procedure, payload, options, transformer) {
15
- const call = this.protocol.createCall(namespace, procedure, options);
14
+ async call(procedure, payload, options, transformer) {
15
+ const call = this.protocol.createCall(procedure, options);
16
16
  const headers = new Headers();
17
17
  headers.set('Content-Type', this.protocol.contentType);
18
18
  headers.set('Accept', this.protocol.contentType);
@@ -21,13 +21,11 @@ export class HttpClientTransport extends EventEmitter {
21
21
  const isBlob = payload instanceof ProtocolBlob;
22
22
  if (isBlob)
23
23
  headers.set('x-neemata-blob', 'true');
24
- const response = fetch(`${this.options.origin}/api/${namespace}/${procedure}`, {
24
+ const response = fetch(`${this.options.origin}/api/${procedure}`, {
25
25
  method: 'POST',
26
26
  headers,
27
27
  credentials: 'include',
28
- body: isBlob
29
- ? payload.source
30
- : transformer.encodeRPC(namespace, procedure, payload),
28
+ body: isBlob ? payload.source : transformer.encodeRPC(procedure, payload),
31
29
  signal: call.signal,
32
30
  // @ts-expect-error
33
31
  duplex: 'half',
@@ -42,10 +40,7 @@ export class HttpClientTransport extends EventEmitter {
42
40
  ? Number.parseInt(contentLength) || undefined
43
41
  : undefined;
44
42
  const type = response.headers.get('content-type') || 'application/octet-stream';
45
- const stream = new ProtocolServerBlobStream(-1, {
46
- size,
47
- type,
48
- });
43
+ const stream = new ProtocolServerBlobStream(-1, { size, type });
49
44
  response.body?.pipeThrough(stream);
50
45
  return stream;
51
46
  }
@@ -54,7 +49,7 @@ export class HttpClientTransport extends EventEmitter {
54
49
  return body.then((buffer) => {
55
50
  if (response.ok) {
56
51
  const decoded = this.protocol.format.decode(buffer);
57
- return transformer.decodeRPC(namespace, procedure, decoded);
52
+ return transformer.decodeRPC(procedure, decoded);
58
53
  }
59
54
  else {
60
55
  if (buffer.byteLength === 0) {
@@ -81,7 +76,7 @@ export class HttpClientTransport extends EventEmitter {
81
76
  async disconnect() {
82
77
  this.emit('disconnected', 'client');
83
78
  }
84
- async send(messageType, buffer, metadata) {
79
+ async send(_messageType, _buffer, _metadata) {
85
80
  throw new Error('Not supported');
86
81
  }
87
82
  }
package/package.json CHANGED
@@ -9,21 +9,21 @@
9
9
  }
10
10
  },
11
11
  "dependencies": {
12
- "@nmtjs/protocol": "0.13.0",
13
- "@nmtjs/client": "0.13.0",
14
- "@nmtjs/common": "0.13.0"
12
+ "@nmtjs/client": "0.14.0",
13
+ "@nmtjs/common": "0.14.0",
14
+ "@nmtjs/protocol": "0.14.0"
15
15
  },
16
16
  "peerDependencies": {
17
- "@nmtjs/client": "0.13.0",
18
- "@nmtjs/common": "0.13.0",
19
- "@nmtjs/protocol": "0.13.0"
17
+ "@nmtjs/common": "0.14.0",
18
+ "@nmtjs/client": "0.14.0",
19
+ "@nmtjs/protocol": "0.14.0"
20
20
  },
21
21
  "files": [
22
22
  "dist",
23
23
  "LICENSE.md",
24
24
  "README.md"
25
25
  ],
26
- "version": "0.13.0",
26
+ "version": "0.14.0",
27
27
  "scripts": {
28
28
  "build": "tsc",
29
29
  "type-check": "tsc --noEmit"