@nmtjs/http-client 0.14.4 → 0.15.0-beta.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.
- package/LICENSE.md +1 -1
- package/README.md +1 -1
- package/package.json +9 -7
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -84
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c)
|
|
1
|
+
Copyright (c) 2025 Denys Ilchyshyn
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -9,23 +9,25 @@
|
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@nmtjs/client": "0.
|
|
13
|
-
"@nmtjs/common": "0.
|
|
14
|
-
"@nmtjs/protocol": "0.
|
|
12
|
+
"@nmtjs/client": "0.15.0-beta.1",
|
|
13
|
+
"@nmtjs/common": "0.15.0-beta.1",
|
|
14
|
+
"@nmtjs/protocol": "0.15.0-beta.1"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@nmtjs/common": "0.
|
|
18
|
-
"@nmtjs/
|
|
19
|
-
"@nmtjs/
|
|
17
|
+
"@nmtjs/common": "0.15.0-beta.1",
|
|
18
|
+
"@nmtjs/protocol": "0.15.0-beta.1",
|
|
19
|
+
"@nmtjs/client": "0.15.0-beta.1"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
23
23
|
"LICENSE.md",
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
|
-
"version": "0.
|
|
26
|
+
"version": "0.15.0-beta.1",
|
|
27
27
|
"scripts": {
|
|
28
|
+
"clean-build": "rm -rf ./dist",
|
|
28
29
|
"build": "tsc",
|
|
30
|
+
"dev": "tsc --watch",
|
|
29
31
|
"type-check": "tsc --noEmit"
|
|
30
32
|
}
|
|
31
33
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ClientMessageType } from '@nmtjs/protocol';
|
|
2
|
-
import type { BaseProtocol, ProtocolBaseClientCallOptions, ProtocolBaseTransformer, ProtocolClientCall, ProtocolSendMetadata } from '@nmtjs/protocol/client';
|
|
3
|
-
import { ProtocolTransport, ProtocolTransportStatus } from '@nmtjs/protocol/client';
|
|
4
|
-
export type HttpClientTransportOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* The origin of the server
|
|
7
|
-
* @example 'http://localhost:3000'
|
|
8
|
-
*/
|
|
9
|
-
origin: string;
|
|
10
|
-
debug?: boolean;
|
|
11
|
-
};
|
|
12
|
-
export declare class HttpClientTransport extends ProtocolTransport<HttpClientTransportOptions> {
|
|
13
|
-
#private;
|
|
14
|
-
protected readonly protocol: BaseProtocol;
|
|
15
|
-
protected readonly options: HttpClientTransportOptions;
|
|
16
|
-
status: ProtocolTransportStatus;
|
|
17
|
-
constructor(protocol: BaseProtocol, options: HttpClientTransportOptions);
|
|
18
|
-
call(procedure: string, payload: any, options: ProtocolBaseClientCallOptions, transformer: ProtocolBaseTransformer): Promise<ProtocolClientCall>;
|
|
19
|
-
connect(auth: any): Promise<void>;
|
|
20
|
-
disconnect(): Promise<void>;
|
|
21
|
-
send(_messageType: ClientMessageType, _buffer: ArrayBuffer, _metadata: ProtocolSendMetadata): Promise<void>;
|
|
22
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ClientError } from '@nmtjs/client';
|
|
2
|
-
import { ErrorCode, ProtocolBlob } from '@nmtjs/protocol';
|
|
3
|
-
import { ProtocolServerBlobStream, ProtocolTransport, ProtocolTransportStatus, } from '@nmtjs/protocol/client';
|
|
4
|
-
export class HttpClientTransport extends ProtocolTransport {
|
|
5
|
-
protocol;
|
|
6
|
-
options;
|
|
7
|
-
#auth = null;
|
|
8
|
-
status = ProtocolTransportStatus.CONNECTED;
|
|
9
|
-
constructor(protocol, options) {
|
|
10
|
-
super();
|
|
11
|
-
this.protocol = protocol;
|
|
12
|
-
this.options = options;
|
|
13
|
-
}
|
|
14
|
-
async call(procedure, payload, options, transformer) {
|
|
15
|
-
const call = this.protocol.createCall(procedure, options);
|
|
16
|
-
const headers = new Headers();
|
|
17
|
-
headers.set('Content-Type', this.protocol.contentType);
|
|
18
|
-
headers.set('Accept', this.protocol.contentType);
|
|
19
|
-
if (this.#auth)
|
|
20
|
-
headers.set('Authorization', this.#auth);
|
|
21
|
-
const isBlob = payload instanceof ProtocolBlob;
|
|
22
|
-
if (isBlob)
|
|
23
|
-
headers.set('x-neemata-blob', 'true');
|
|
24
|
-
const response = fetch(`${this.options.origin}/api/${procedure}`, {
|
|
25
|
-
method: 'POST',
|
|
26
|
-
headers,
|
|
27
|
-
credentials: 'include',
|
|
28
|
-
body: isBlob
|
|
29
|
-
? payload.source
|
|
30
|
-
: this.protocol.format.encode(transformer.encodeRPC(procedure, payload)),
|
|
31
|
-
signal: call.signal,
|
|
32
|
-
// @ts-expect-error
|
|
33
|
-
duplex: 'half',
|
|
34
|
-
});
|
|
35
|
-
response
|
|
36
|
-
.catch((error) => Promise.reject(new Error('Network error', { cause: error })))
|
|
37
|
-
.then((response) => {
|
|
38
|
-
const isBlob = response.headers.get('x-neemata-blob') === 'true';
|
|
39
|
-
if (isBlob) {
|
|
40
|
-
const contentLength = response.headers.get('content-length');
|
|
41
|
-
const size = contentLength
|
|
42
|
-
? Number.parseInt(contentLength, 10) || undefined
|
|
43
|
-
: undefined;
|
|
44
|
-
const type = response.headers.get('content-type') || 'application/octet-stream';
|
|
45
|
-
const stream = new ProtocolServerBlobStream(-1, { size, type });
|
|
46
|
-
response.body?.pipeThrough(stream);
|
|
47
|
-
return stream;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const body = response.arrayBuffer();
|
|
51
|
-
return body.then((buffer) => {
|
|
52
|
-
if (response.ok) {
|
|
53
|
-
const decoded = this.protocol.format.decode(buffer);
|
|
54
|
-
return transformer.decodeRPC(procedure, decoded);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
if (buffer.byteLength === 0) {
|
|
58
|
-
const error = new ClientError(ErrorCode.InternalServerError, `Empty response with ${response.status} status code`);
|
|
59
|
-
return Promise.reject(error);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
const payload = this.protocol.format.decode(buffer);
|
|
63
|
-
const error = new ClientError(payload.code, payload.message, payload.data);
|
|
64
|
-
return Promise.reject(error);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
.then(call.resolve)
|
|
71
|
-
.catch(call.reject);
|
|
72
|
-
return call;
|
|
73
|
-
}
|
|
74
|
-
async connect(auth) {
|
|
75
|
-
this.#auth = auth;
|
|
76
|
-
this.emit('connected');
|
|
77
|
-
}
|
|
78
|
-
async disconnect() {
|
|
79
|
-
this.emit('disconnected', 'client');
|
|
80
|
-
}
|
|
81
|
-
async send(_messageType, _buffer, _metadata) {
|
|
82
|
-
throw new Error('Not supported');
|
|
83
|
-
}
|
|
84
|
-
}
|