@nmtjs/protocol 0.15.0-beta.9 → 0.15.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/README.md +31 -1
- package/dist/client/index.js +5 -5
- package/dist/client/protocol.d.ts +11 -2
- package/dist/client/protocol.js +1 -1
- package/dist/client/protocol.js.map +1 -1
- package/dist/client/stream.js +9 -18
- package/dist/client/stream.js.map +1 -1
- package/dist/client/versions/v1.d.ts +67 -36
- package/dist/client/versions/v1.js +18 -6
- package/dist/client/versions/v1.js.map +1 -1
- package/dist/common/binary.d.ts +3 -5
- package/dist/common/binary.js.map +1 -1
- package/dist/common/blob.d.ts +3 -3
- package/dist/common/blob.js +3 -3
- package/dist/common/blob.js.map +1 -1
- package/dist/common/enums.d.ts +4 -1
- package/dist/common/enums.js +16 -7
- package/dist/common/enums.js.map +1 -1
- package/dist/common/index.js +6 -6
- package/dist/common/utils.js +1 -1
- package/dist/common/utils.js.map +1 -1
- package/dist/server/format.d.ts +5 -3
- package/dist/server/format.js +2 -0
- package/dist/server/format.js.map +1 -1
- package/dist/server/index.js +7 -7
- package/dist/server/protocol.d.ts +12 -3
- package/dist/server/protocol.js +1 -1
- package/dist/server/protocol.js.map +1 -1
- package/dist/server/stream.d.ts +3 -0
- package/dist/server/stream.js +20 -1
- package/dist/server/stream.js.map +1 -1
- package/dist/server/utils.js +4 -4
- package/dist/server/utils.js.map +1 -1
- package/dist/server/versions/v1.d.ts +45 -28
- package/dist/server/versions/v1.js +19 -7
- package/dist/server/versions/v1.js.map +1 -1
- package/package.json +26 -16
- package/src/client/protocol.ts +4 -1
- package/src/client/stream.ts +8 -19
- package/src/client/versions/v1.ts +20 -5
- package/src/common/blob.ts +4 -9
- package/src/common/enums.ts +6 -1
- package/src/server/format.ts +7 -3
- package/src/server/protocol.ts +4 -1
- package/src/server/stream.ts +22 -1
- package/src/server/utils.ts +5 -5
- package/src/server/versions/v1.ts +24 -4
package/dist/server/format.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Pattern } from '@nmtjs/common';
|
|
2
|
+
import type { ProtocolBlobMetadata } from '../common/blob.ts';
|
|
2
3
|
import type { DecodeRPCContext, EncodeRPCStreams, ProtocolRPCPayload } from '../common/types.ts';
|
|
3
4
|
import type { ProtocolClientStream } from './stream.ts';
|
|
4
5
|
export interface BaseServerDecoder {
|
|
@@ -10,14 +11,14 @@ export interface BaseServerEncoder {
|
|
|
10
11
|
contentType: string;
|
|
11
12
|
encode(data: unknown): ArrayBufferView;
|
|
12
13
|
encodeRPC(data: unknown, streams: EncodeRPCStreams): ArrayBufferView;
|
|
13
|
-
encodeBlob(streamId: number): unknown;
|
|
14
|
+
encodeBlob(streamId: number, metadata: ProtocolBlobMetadata): unknown;
|
|
14
15
|
}
|
|
15
16
|
export declare abstract class BaseServerFormat implements BaseServerDecoder, BaseServerEncoder {
|
|
16
17
|
abstract accept: Pattern[];
|
|
17
18
|
abstract contentType: string;
|
|
18
19
|
abstract encode(data: unknown): ArrayBufferView;
|
|
19
20
|
abstract encodeRPC(data: unknown, streams: EncodeRPCStreams): ArrayBufferView;
|
|
20
|
-
abstract encodeBlob(streamId: number): unknown;
|
|
21
|
+
abstract encodeBlob(streamId: number, metadata: ProtocolBlobMetadata): unknown;
|
|
21
22
|
abstract decode(buffer: ArrayBufferView): any;
|
|
22
23
|
abstract decodeRPC(buffer: ArrayBufferView, context: DecodeRPCContext<() => ProtocolClientStream>): ProtocolRPCPayload;
|
|
23
24
|
}
|
|
@@ -25,7 +26,8 @@ export declare const parseContentTypes: (types: string) => string[];
|
|
|
25
26
|
export declare class ProtocolFormats {
|
|
26
27
|
decoders: Map<Pattern, BaseServerDecoder>;
|
|
27
28
|
encoders: Map<Pattern, BaseServerEncoder>;
|
|
28
|
-
|
|
29
|
+
default: BaseServerFormat;
|
|
30
|
+
constructor(formats: [BaseServerFormat, ...BaseServerFormat[]]);
|
|
29
31
|
supportsDecoder(contentType: string, throwIfUnsupported?: boolean): BaseServerDecoder | null;
|
|
30
32
|
supportsEncoder(contentType: string, throwIfUnsupported?: boolean): BaseServerEncoder | null;
|
|
31
33
|
private supports;
|
package/dist/server/format.js
CHANGED
|
@@ -32,7 +32,9 @@ export const parseContentTypes = (types) => {
|
|
|
32
32
|
export class ProtocolFormats {
|
|
33
33
|
decoders = new Map();
|
|
34
34
|
encoders = new Map();
|
|
35
|
+
default;
|
|
35
36
|
constructor(formats) {
|
|
37
|
+
this.default = formats[0];
|
|
36
38
|
for (const format of formats) {
|
|
37
39
|
this.encoders.set(format.contentType, format);
|
|
38
40
|
for (const acceptType of format.accept) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/server/format.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/server/format.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AA0BrC,MAAM,OAAgB,gBAAgB;CAcrC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC;IAClD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAC/B,IAAI,UAAU,KAAK,KAAK;QAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IACxC,OAAO,UAAU;SACd,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACV,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACvC,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,E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AC;gBACvC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;IAAA,CACF;IAED,eAAe,CAAC,WAAmB,EAAE,kBAAkB,GAAG,KAAK,EAAE;QAC/D,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAA;IAAA,CACrE;IAED,eAAe,CAAC,WAAmB,EAAE,kBAAkB,GAAG,KAAK,EAAE;QAC/D,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,kBAAkB,CAAC,CAAA;IAAA,CACrE;IAEO,QAAQ,CACd,OAAwB,EACxB,WAAmB,EACnB,kBAAkB,GAAG,KAAK,EAChB;QACV,0EAA0E;QAC1E,MAAM,KAAK,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAA;QAE5C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACxC,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC;oBAAE,OAAO,MAAM,CAAA;YAC3D,CAAC;QACH,CAAC;QAED,IAAI,kBAAkB;YACpB,MAAM,IAAI,KAAK,CAAC,8BAA8B,WAAW,EAAE,CAAC,CAAA;QAE9D,OAAO,IAAI,CAAA;IAAA,CACZ;CACF"}
|
package/dist/server/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
import { ProtocolVersion } from
|
|
7
|
-
import { ProtocolVersion1 } from
|
|
1
|
+
export * from './format.js';
|
|
2
|
+
export * from './protocol.js';
|
|
3
|
+
export * from './stream.js';
|
|
4
|
+
export * from './types.js';
|
|
5
|
+
export * from './utils.js';
|
|
6
|
+
import { ProtocolVersion } from '../common/enums.js';
|
|
7
|
+
import { ProtocolVersion1 } from './versions/v1.js';
|
|
8
8
|
export const versions = { [ProtocolVersion.v1]: new ProtocolVersion1() };
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -44,6 +44,12 @@ export type ServerMessageTypePayload = {
|
|
|
44
44
|
[ServerMessageType.RpcStreamResponse]: {
|
|
45
45
|
callId: number;
|
|
46
46
|
};
|
|
47
|
+
[ServerMessageType.Pong]: {
|
|
48
|
+
nonce: number;
|
|
49
|
+
};
|
|
50
|
+
[ServerMessageType.Ping]: {
|
|
51
|
+
nonce: number;
|
|
52
|
+
};
|
|
47
53
|
[ServerMessageType.ClientStreamAbort]: {
|
|
48
54
|
streamId: number;
|
|
49
55
|
reason?: string;
|
|
@@ -73,13 +79,16 @@ export type ClientMessageTypePayload = {
|
|
|
73
79
|
streams?: EncodeRPCStreams;
|
|
74
80
|
};
|
|
75
81
|
};
|
|
76
|
-
[ClientMessageType.RpcPull]: {
|
|
77
|
-
callId: number;
|
|
78
|
-
};
|
|
79
82
|
[ClientMessageType.RpcAbort]: {
|
|
80
83
|
callId: number;
|
|
81
84
|
reason?: string;
|
|
82
85
|
};
|
|
86
|
+
[ClientMessageType.Ping]: {
|
|
87
|
+
nonce: number;
|
|
88
|
+
};
|
|
89
|
+
[ClientMessageType.Pong]: {
|
|
90
|
+
nonce: number;
|
|
91
|
+
};
|
|
83
92
|
[ClientMessageType.ClientStreamPush]: {
|
|
84
93
|
streamId: number;
|
|
85
94
|
chunk: ArrayBufferView;
|
package/dist/server/protocol.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/server/protocol.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,IAAI,CAAQ;IACZ,IAAI,CAAM;IAEV,YAAY,IAAY,EAAE,OAAgB,EAAE,IAAU;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/server/protocol.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,IAAI,CAAQ;IACZ,IAAI,CAAM;IAEV,YAAY,IAAY,EAAE,OAAgB,EAAE,IAAU,EAAE;QACtD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAAA,CACjB;IAED,IAAI,OAAO,GAAG;QACZ,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,CAAA;IAAA,CACvC;IAED,QAAQ,GAAG;QACT,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAA;IAAA,CACtC;IAED,MAAM,GAAG;QACP,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAA;IAAA,CACnE;CACF;AAED,MAAM,OAAgB,wBAAwB;IAgBlC,MAAM,CACd,GAAG,MAAyC,EAC3B;QACjB,OAAO,MAAM,CAAC,GAAG,MAAM,CAAC,CAAA;IAAA,CACzB;CACF"}
|
package/dist/server/stream.d.ts
CHANGED
|
@@ -9,7 +9,10 @@ export declare class ProtocolClientStream extends PassThrough {
|
|
|
9
9
|
_read(size: number): void;
|
|
10
10
|
}
|
|
11
11
|
export declare class ProtocolServerStream extends PassThrough {
|
|
12
|
+
#private;
|
|
12
13
|
readonly id: number;
|
|
13
14
|
readonly metadata: ProtocolBlobMetadata;
|
|
14
15
|
constructor(id: number, blob: ProtocolBlob);
|
|
16
|
+
resume(): this;
|
|
17
|
+
destroy(error?: Error | null): this;
|
|
15
18
|
}
|
package/dist/server/stream.js
CHANGED
|
@@ -21,6 +21,8 @@ export class ProtocolClientStream extends PassThrough {
|
|
|
21
21
|
export class ProtocolServerStream extends PassThrough {
|
|
22
22
|
id;
|
|
23
23
|
metadata;
|
|
24
|
+
#source;
|
|
25
|
+
#piped = false;
|
|
24
26
|
constructor(id, blob) {
|
|
25
27
|
let readable;
|
|
26
28
|
if (blob.source instanceof Readable) {
|
|
@@ -34,9 +36,26 @@ export class ProtocolServerStream extends PassThrough {
|
|
|
34
36
|
}
|
|
35
37
|
super();
|
|
36
38
|
this.pause();
|
|
37
|
-
readable
|
|
39
|
+
this.#source = readable;
|
|
40
|
+
this.#source.on('error', (error) => {
|
|
41
|
+
this.destroy(error);
|
|
42
|
+
});
|
|
38
43
|
this.id = id;
|
|
39
44
|
this.metadata = blob.metadata;
|
|
40
45
|
}
|
|
46
|
+
resume() {
|
|
47
|
+
if (!this.#piped) {
|
|
48
|
+
this.#piped = true;
|
|
49
|
+
this.#source.pipe(this);
|
|
50
|
+
}
|
|
51
|
+
return super.resume();
|
|
52
|
+
}
|
|
53
|
+
destroy(error) {
|
|
54
|
+
if (!this.#piped) {
|
|
55
|
+
this.#piped = true;
|
|
56
|
+
}
|
|
57
|
+
this.#source.destroy?.(error ?? undefined);
|
|
58
|
+
return super.destroy(error ?? undefined);
|
|
59
|
+
}
|
|
41
60
|
}
|
|
42
61
|
//# sourceMappingURL=stream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/server/stream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAIhD,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAIjC;
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"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E,CAAA;QAEP,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAA;QACvB,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;YAClC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAAA,CACpB,CAAC,CAAA;QAEF,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;IAAA,CAC9B;IAEQ,MAAM,GAAS;QACtB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;YAClB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;QACD,OAAO,KAAK,CAAC,MAAM,EAAE,CAAA;IAAA,CACtB;IAEQ,OAAO,CAAC,KAAoB,EAAE;QACrC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA;QACpB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,SAAS,CAAC,CAAA;QAC1C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,SAAS,CAAC,CAAA;IAAA,CACzC;CACF"}
|
package/dist/server/utils.js
CHANGED
|
@@ -5,12 +5,12 @@ export class UnsupportedContentTypeError extends UnsupportedFormatError {
|
|
|
5
5
|
export class UnsupportedAcceptTypeError extends UnsupportedFormatError {
|
|
6
6
|
}
|
|
7
7
|
export const getFormat = (format, { accept, contentType }) => {
|
|
8
|
-
const encoder =
|
|
8
|
+
const encoder = accept ? format.supportsEncoder(accept) : undefined;
|
|
9
9
|
if (!encoder)
|
|
10
|
-
throw new UnsupportedContentTypeError('Unsupported Content type');
|
|
11
|
-
const decoder = accept ? format.supportsDecoder(accept) : undefined;
|
|
12
|
-
if (!decoder)
|
|
13
10
|
throw new UnsupportedAcceptTypeError('Unsupported Accept type');
|
|
11
|
+
const decoder = contentType ? format.supportsDecoder(contentType) : undefined;
|
|
12
|
+
if (!decoder)
|
|
13
|
+
throw new UnsupportedContentTypeError('Unsupported Content type');
|
|
14
14
|
return { encoder, decoder };
|
|
15
15
|
};
|
|
16
16
|
//# sourceMappingURL=utils.js.map
|
package/dist/server/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,sBAAuB,SAAQ,KAAK;CAAG;AAEpD,MAAM,OAAO,2BAA4B,SAAQ,sBAAsB;CAAG;AAE1E,MAAM,OAAO,0BAA2B,SAAQ,sBAAsB;CAAG;AAEzE,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,MAAuB,EACvB,EAAE,MAAM,EAAE,WAAW,EAAuB,EAC5C,EAAE;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/server/utils.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,sBAAuB,SAAQ,KAAK;CAAG;AAEpD,MAAM,OAAO,2BAA4B,SAAQ,sBAAsB;CAAG;AAE1E,MAAM,OAAO,0BAA2B,SAAQ,sBAAsB;CAAG;AAEzE,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,MAAuB,EACvB,EAAE,MAAM,EAAE,WAAW,EAAuB,EAC5C,EAAE,CAAC;IACH,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACnE,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,0BAA0B,CAAC,yBAAyB,CAAC,CAAA;IAE7E,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC7E,IAAI,CAAC,OAAO;QACV,MAAM,IAAI,2BAA2B,CAAC,0BAA0B,CAAC,CAAA;IAEnE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;AAAA,CAC5B,CAAA"}
|
|
@@ -5,73 +5,90 @@ import { ProtocolVersionInterface } from '../protocol.ts';
|
|
|
5
5
|
export declare class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
6
6
|
version: ProtocolVersion;
|
|
7
7
|
decodeMessage(context: MessageContext, buffer: Buffer): {
|
|
8
|
+
callId?: undefined;
|
|
9
|
+
nonce?: undefined;
|
|
10
|
+
size?: undefined;
|
|
11
|
+
chunk?: undefined;
|
|
12
|
+
streamId?: undefined;
|
|
13
|
+
reason?: undefined;
|
|
8
14
|
type: ClientMessageType.Rpc;
|
|
9
15
|
rpc: {
|
|
10
16
|
callId: number;
|
|
11
17
|
procedure: string;
|
|
12
18
|
payload: unknown;
|
|
13
19
|
};
|
|
14
|
-
callId?: undefined;
|
|
15
|
-
reason?: undefined;
|
|
16
|
-
streamId?: undefined;
|
|
17
|
-
size?: undefined;
|
|
18
|
-
chunk?: undefined;
|
|
19
20
|
} | {
|
|
20
|
-
|
|
21
|
-
callId: number;
|
|
22
|
-
rpc?: undefined;
|
|
23
|
-
reason?: undefined;
|
|
24
|
-
streamId?: undefined;
|
|
21
|
+
nonce?: undefined;
|
|
25
22
|
size?: undefined;
|
|
26
23
|
chunk?: undefined;
|
|
27
|
-
|
|
24
|
+
streamId?: undefined;
|
|
25
|
+
rpc?: undefined;
|
|
28
26
|
type: ClientMessageType.RpcAbort;
|
|
29
27
|
callId: number;
|
|
30
28
|
reason: string | undefined;
|
|
31
|
-
|
|
29
|
+
} | {
|
|
30
|
+
callId?: undefined;
|
|
31
|
+
size?: undefined;
|
|
32
|
+
chunk?: undefined;
|
|
32
33
|
streamId?: undefined;
|
|
34
|
+
reason?: undefined;
|
|
35
|
+
rpc?: undefined;
|
|
36
|
+
type: ClientMessageType.Ping;
|
|
37
|
+
nonce: number;
|
|
38
|
+
} | {
|
|
39
|
+
callId?: undefined;
|
|
33
40
|
size?: undefined;
|
|
34
41
|
chunk?: undefined;
|
|
42
|
+
streamId?: undefined;
|
|
43
|
+
reason?: undefined;
|
|
44
|
+
rpc?: undefined;
|
|
45
|
+
type: ClientMessageType.Pong;
|
|
46
|
+
nonce: number;
|
|
35
47
|
} | {
|
|
48
|
+
callId?: undefined;
|
|
49
|
+
nonce?: undefined;
|
|
50
|
+
size?: undefined;
|
|
51
|
+
chunk?: undefined;
|
|
52
|
+
rpc?: undefined;
|
|
36
53
|
type: ClientMessageType.ServerStreamAbort;
|
|
37
54
|
streamId: number;
|
|
38
55
|
reason: string | undefined;
|
|
39
|
-
|
|
56
|
+
} | {
|
|
40
57
|
callId?: undefined;
|
|
41
|
-
|
|
58
|
+
nonce?: undefined;
|
|
42
59
|
chunk?: undefined;
|
|
43
|
-
|
|
60
|
+
reason?: undefined;
|
|
61
|
+
rpc?: undefined;
|
|
44
62
|
type: ClientMessageType.ServerStreamPull;
|
|
45
63
|
streamId: number;
|
|
46
64
|
size: number;
|
|
47
|
-
|
|
65
|
+
} | {
|
|
48
66
|
callId?: undefined;
|
|
49
|
-
|
|
67
|
+
nonce?: undefined;
|
|
68
|
+
size?: undefined;
|
|
50
69
|
chunk?: undefined;
|
|
51
|
-
|
|
70
|
+
rpc?: undefined;
|
|
52
71
|
type: ClientMessageType.ClientStreamAbort;
|
|
53
72
|
streamId: number;
|
|
54
73
|
reason: string | undefined;
|
|
55
|
-
|
|
74
|
+
} | {
|
|
56
75
|
callId?: undefined;
|
|
76
|
+
nonce?: undefined;
|
|
57
77
|
size?: undefined;
|
|
58
78
|
chunk?: undefined;
|
|
59
|
-
|
|
79
|
+
reason?: undefined;
|
|
80
|
+
rpc?: undefined;
|
|
60
81
|
type: ClientMessageType.ClientStreamEnd;
|
|
61
82
|
streamId: number;
|
|
62
|
-
|
|
83
|
+
} | {
|
|
63
84
|
callId?: undefined;
|
|
64
|
-
|
|
85
|
+
nonce?: undefined;
|
|
65
86
|
size?: undefined;
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
reason?: undefined;
|
|
88
|
+
rpc?: undefined;
|
|
68
89
|
type: ClientMessageType.ClientStreamPush;
|
|
69
90
|
streamId: number;
|
|
70
91
|
chunk: Buffer<ArrayBufferLike>;
|
|
71
|
-
rpc?: undefined;
|
|
72
|
-
callId?: undefined;
|
|
73
|
-
reason?: undefined;
|
|
74
|
-
size?: undefined;
|
|
75
92
|
};
|
|
76
93
|
encodeMessage<T extends ServerMessageType>(context: MessageContext, messageType: T, payload: ServerMessageTypePayload[T]): ArrayBufferView<ArrayBufferLike>;
|
|
77
94
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { decodeText, encodeNumber, encodeText } from
|
|
2
|
-
import { ClientMessageType, MessageByteLength, ProtocolVersion, ServerMessageType, } from
|
|
3
|
-
import { ProtocolVersionInterface } from
|
|
1
|
+
import { decodeText, encodeNumber, encodeText } from '../../common/binary.js';
|
|
2
|
+
import { ClientMessageType, MessageByteLength, ProtocolVersion, ServerMessageType, } from '../../common/enums.js';
|
|
3
|
+
import { ProtocolVersionInterface } from '../protocol.js';
|
|
4
4
|
export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
5
5
|
version = ProtocolVersion.v1;
|
|
6
6
|
decodeMessage(context, buffer) {
|
|
@@ -20,16 +20,20 @@ export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
|
20
20
|
});
|
|
21
21
|
return { type: messageType, rpc: { callId, procedure, payload } };
|
|
22
22
|
}
|
|
23
|
-
case ClientMessageType.RpcPull: {
|
|
24
|
-
const callId = messagePayload.readUInt32LE(0);
|
|
25
|
-
return { type: messageType, callId };
|
|
26
|
-
}
|
|
27
23
|
case ClientMessageType.RpcAbort: {
|
|
28
24
|
const callId = messagePayload.readUInt32LE(0);
|
|
29
25
|
const reasonPayload = messagePayload.subarray(MessageByteLength.CallId);
|
|
30
26
|
const reason = reasonPayload.byteLength > 0 ? decodeText(reasonPayload) : undefined;
|
|
31
27
|
return { type: messageType, callId, reason };
|
|
32
28
|
}
|
|
29
|
+
case ClientMessageType.Ping: {
|
|
30
|
+
const nonce = messagePayload.readUInt32LE(0);
|
|
31
|
+
return { type: messageType, nonce };
|
|
32
|
+
}
|
|
33
|
+
case ClientMessageType.Pong: {
|
|
34
|
+
const nonce = messagePayload.readUInt32LE(0);
|
|
35
|
+
return { type: messageType, nonce };
|
|
36
|
+
}
|
|
33
37
|
case ClientMessageType.ServerStreamAbort: {
|
|
34
38
|
const streamId = messagePayload.readUInt32LE(0);
|
|
35
39
|
const reasonPayload = messagePayload.subarray(MessageByteLength.StreamId);
|
|
@@ -91,6 +95,14 @@ export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
|
91
95
|
const { callId, reason } = payload;
|
|
92
96
|
return this.encode(encodeNumber(messageType, 'Uint8'), encodeNumber(callId, 'Uint32'), reason ? encodeText(reason) : Buffer.alloc(0));
|
|
93
97
|
}
|
|
98
|
+
case ServerMessageType.Pong: {
|
|
99
|
+
const { nonce } = payload;
|
|
100
|
+
return this.encode(encodeNumber(messageType, 'Uint8'), encodeNumber(nonce, 'Uint32'));
|
|
101
|
+
}
|
|
102
|
+
case ServerMessageType.Ping: {
|
|
103
|
+
const { nonce } = payload;
|
|
104
|
+
return this.encode(encodeNumber(messageType, 'Uint8'), encodeNumber(nonce, 'Uint32'));
|
|
105
|
+
}
|
|
94
106
|
case ServerMessageType.ClientStreamPull: {
|
|
95
107
|
const { size, streamId } = payload;
|
|
96
108
|
return this.encode(encodeNumber(messageType, 'Uint8'), encodeNumber(streamId, 'Uint32'), encodeNumber(size, 'Uint32'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.js","sourceRoot":"","sources":["../../../src/server/versions/v1.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UA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iBAAiB,CAAC,eAAe,EAAE,CAAC;gBACvC,MAAM,EAAE,QAAQ,EAAE,GAChB,OAAsE,CAAA;gBACxE,OAAO,IAAI,CAAC,MAAM,CAChB,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,EAClC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,CACjC,CAAA;YACH,CAAC;YACD,KAAK,iBAAiB,CAAC,iBAAiB,EAAE,CAAC;gBACzC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GACxB,OAAwE,CAAA;gBAC1E,OAAO,IAAI,CAAC,MAAM,CAChB,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,EAClC,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAChC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAC9C,CAAA;YACH,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,WAAW,EAAE,CAAC,CAAA;QAC/D,CAAC;IAAA,CACF;CACF"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nmtjs/protocol",
|
|
3
|
+
"description": "Binary protocol implementation for Neemata clients and servers.",
|
|
3
4
|
"type": "module",
|
|
4
5
|
"exports": {
|
|
5
|
-
".":
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/common/index.d.ts",
|
|
8
|
+
"import": "./dist/common/index.js",
|
|
9
|
+
"module-sync": "./dist/common/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./server": {
|
|
12
|
+
"types": "./dist/server/index.d.ts",
|
|
13
|
+
"import": "./dist/server/index.js",
|
|
14
|
+
"module-sync": "./dist/server/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./client": {
|
|
17
|
+
"types": "./dist/client/index.d.ts",
|
|
18
|
+
"import": "./dist/client/index.js",
|
|
19
|
+
"module-sync": "./dist/client/index.js"
|
|
20
|
+
}
|
|
8
21
|
},
|
|
9
22
|
"dependencies": {
|
|
10
23
|
"hookable": "6.0.0-rc.1",
|
|
11
|
-
"@nmtjs/
|
|
12
|
-
"@nmtjs/
|
|
13
|
-
"@nmtjs/
|
|
24
|
+
"@nmtjs/common": "0.15.0",
|
|
25
|
+
"@nmtjs/type": "0.15.0",
|
|
26
|
+
"@nmtjs/contract": "0.15.0"
|
|
14
27
|
},
|
|
15
28
|
"devDependencies": {
|
|
16
|
-
"@nmtjs/core": "0.15.0
|
|
29
|
+
"@nmtjs/core": "0.15.0"
|
|
17
30
|
},
|
|
18
31
|
"peerDependencies": {
|
|
19
|
-
"@nmtjs/
|
|
20
|
-
"@nmtjs/
|
|
21
|
-
"@nmtjs/
|
|
22
|
-
"@nmtjs/
|
|
32
|
+
"@nmtjs/core": "0.15.0",
|
|
33
|
+
"@nmtjs/common": "0.15.0",
|
|
34
|
+
"@nmtjs/contract": "0.15.0",
|
|
35
|
+
"@nmtjs/type": "0.15.0"
|
|
23
36
|
},
|
|
24
37
|
"files": [
|
|
25
38
|
"dist",
|
|
@@ -27,11 +40,8 @@
|
|
|
27
40
|
"LICENSE.md",
|
|
28
41
|
"README.md"
|
|
29
42
|
],
|
|
30
|
-
"version": "0.15.0
|
|
43
|
+
"version": "0.15.0",
|
|
31
44
|
"scripts": {
|
|
32
|
-
"clean-build": "rm -rf ./dist"
|
|
33
|
-
"build": "tsc --declaration --sourcemap",
|
|
34
|
-
"dev": "tsc --watch",
|
|
35
|
-
"type-check": "tsc --noEmit"
|
|
45
|
+
"clean-build": "rm -rf ./dist"
|
|
36
46
|
}
|
|
37
47
|
}
|
package/src/client/protocol.ts
CHANGED
|
@@ -27,7 +27,8 @@ export type MessageContext = {
|
|
|
27
27
|
export type ClientMessageTypePayload = {
|
|
28
28
|
[ClientMessageType.Rpc]: { callId: number; procedure: string; payload: any }
|
|
29
29
|
[ClientMessageType.RpcAbort]: { callId: number; reason?: string }
|
|
30
|
-
[ClientMessageType.
|
|
30
|
+
[ClientMessageType.Ping]: { nonce: number }
|
|
31
|
+
[ClientMessageType.Pong]: { nonce: number }
|
|
31
32
|
[ClientMessageType.ClientStreamPush]: {
|
|
32
33
|
streamId: number
|
|
33
34
|
chunk: ArrayBufferView
|
|
@@ -52,6 +53,8 @@ export type ServerMessageTypePayload = {
|
|
|
52
53
|
[ServerMessageType.RpcStreamChunk]: { callId: number; chunk: ArrayBufferView }
|
|
53
54
|
[ServerMessageType.RpcStreamEnd]: { callId: number }
|
|
54
55
|
[ServerMessageType.RpcStreamAbort]: { callId: number; reason?: string }
|
|
56
|
+
[ServerMessageType.Pong]: { nonce: number }
|
|
57
|
+
[ServerMessageType.Ping]: { nonce: number }
|
|
55
58
|
[ServerMessageType.ServerStreamAbort]: { streamId: number; reason?: string }
|
|
56
59
|
[ServerMessageType.ServerStreamEnd]: { streamId: number }
|
|
57
60
|
[ServerMessageType.ServerStreamPush]: {
|
package/src/client/stream.ts
CHANGED
|
@@ -34,12 +34,7 @@ export class ProtocolClientBlobStream
|
|
|
34
34
|
controller.close()
|
|
35
35
|
return
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
controller.enqueue(
|
|
39
|
-
chunk instanceof Uint8Array
|
|
40
|
-
? chunk
|
|
41
|
-
: new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength),
|
|
42
|
-
)
|
|
37
|
+
controller.enqueue(value)
|
|
43
38
|
},
|
|
44
39
|
transform: (chunk) => {
|
|
45
40
|
if (chunk instanceof ArrayBuffer) {
|
|
@@ -82,21 +77,15 @@ export class ProtocolClientBlobStream
|
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
async read(size: number) {
|
|
85
|
-
|
|
80
|
+
if (this.#queue.byteLength === 0) {
|
|
86
81
|
const { done, value } = await this.#reader.read()
|
|
87
|
-
if (done)
|
|
88
|
-
|
|
89
|
-
const chunk = this.#queue
|
|
90
|
-
this.#queue = new Uint8Array(0)
|
|
91
|
-
return chunk
|
|
92
|
-
}
|
|
93
|
-
return null
|
|
94
|
-
}
|
|
95
|
-
const buffer = value
|
|
96
|
-
this.#queue = concat(this.#queue, buffer)
|
|
82
|
+
if (done) return null
|
|
83
|
+
this.#queue = concat(this.#queue, value)
|
|
97
84
|
}
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
|
|
86
|
+
const chunkSize = Math.min(size, this.#queue.byteLength)
|
|
87
|
+
const chunk = this.#queue.subarray(0, chunkSize)
|
|
88
|
+
this.#queue = this.#queue.subarray(chunkSize)
|
|
100
89
|
return chunk
|
|
101
90
|
}
|
|
102
91
|
}
|
|
@@ -71,6 +71,14 @@ export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
|
71
71
|
reasonPayload.byteLength > 0 ? decodeText(reasonPayload) : undefined
|
|
72
72
|
return { type: messageType, callId, reason }
|
|
73
73
|
}
|
|
74
|
+
case ServerMessageType.Pong: {
|
|
75
|
+
const nonce = decodeNumber(payload, 'Uint32')
|
|
76
|
+
return { type: messageType, nonce }
|
|
77
|
+
}
|
|
78
|
+
case ServerMessageType.Ping: {
|
|
79
|
+
const nonce = decodeNumber(payload, 'Uint32')
|
|
80
|
+
return { type: messageType, nonce }
|
|
81
|
+
}
|
|
74
82
|
case ServerMessageType.ClientStreamPull: {
|
|
75
83
|
const streamId = decodeNumber(payload, 'Uint32')
|
|
76
84
|
const size = decodeNumber(payload, 'Uint32', MessageByteLength.StreamId)
|
|
@@ -144,13 +152,20 @@ export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
|
144
152
|
reason ? encodeText(reason) : new Uint8Array(0),
|
|
145
153
|
)
|
|
146
154
|
}
|
|
147
|
-
case ClientMessageType.
|
|
148
|
-
const {
|
|
149
|
-
payload as ClientMessageTypePayload[ClientMessageType.
|
|
150
|
-
|
|
155
|
+
case ClientMessageType.Ping: {
|
|
156
|
+
const { nonce } =
|
|
157
|
+
payload as ClientMessageTypePayload[ClientMessageType.Ping]
|
|
151
158
|
return this.encode(
|
|
152
159
|
encodeNumber(messageType, 'Uint8'),
|
|
153
|
-
encodeNumber(
|
|
160
|
+
encodeNumber(nonce, 'Uint32'),
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
case ClientMessageType.Pong: {
|
|
164
|
+
const { nonce } =
|
|
165
|
+
payload as ClientMessageTypePayload[ClientMessageType.Pong]
|
|
166
|
+
return this.encode(
|
|
167
|
+
encodeNumber(messageType, 'Uint8'),
|
|
168
|
+
encodeNumber(nonce, 'Uint32'),
|
|
154
169
|
)
|
|
155
170
|
}
|
|
156
171
|
case ClientMessageType.ClientStreamPush: {
|
package/src/common/blob.ts
CHANGED
|
@@ -16,7 +16,7 @@ export class ProtocolBlob implements ProtocolBlobInterface {
|
|
|
16
16
|
|
|
17
17
|
public readonly source: any
|
|
18
18
|
public readonly metadata: ProtocolBlobMetadata
|
|
19
|
-
public readonly encode?: () => unknown
|
|
19
|
+
public readonly encode?: (metadata: ProtocolBlobMetadata) => unknown
|
|
20
20
|
public readonly toJSON?: () => unknown
|
|
21
21
|
|
|
22
22
|
constructor({
|
|
@@ -51,10 +51,10 @@ export class ProtocolBlob implements ProtocolBlobInterface {
|
|
|
51
51
|
static from(
|
|
52
52
|
_source: any,
|
|
53
53
|
_metadata: { size?: number; type?: string; filename?: string } = {},
|
|
54
|
-
_encode?: () => unknown,
|
|
54
|
+
_encode?: (metadata: ProtocolBlobMetadata) => unknown,
|
|
55
55
|
) {
|
|
56
56
|
let source: any
|
|
57
|
-
const metadata = { ..._metadata }
|
|
57
|
+
const metadata = { type: 'application/octet-stream', ..._metadata }
|
|
58
58
|
|
|
59
59
|
if (_source instanceof globalThis.ReadableStream) {
|
|
60
60
|
source = _source
|
|
@@ -85,15 +85,10 @@ export class ProtocolBlob implements ProtocolBlobInterface {
|
|
|
85
85
|
|
|
86
86
|
return new ProtocolBlob({
|
|
87
87
|
source,
|
|
88
|
-
encode: _encode,
|
|
88
|
+
encode: _encode?.bind(null, metadata),
|
|
89
89
|
size: metadata.size,
|
|
90
90
|
type: metadata.type,
|
|
91
91
|
filename: metadata.filename,
|
|
92
92
|
})
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
// toJSON() {
|
|
96
|
-
// if (!this.encode) throw new Error('Blob format encoder is not defined')
|
|
97
|
-
// return this.encode()
|
|
98
|
-
// }
|
|
99
94
|
}
|
package/src/common/enums.ts
CHANGED
|
@@ -5,7 +5,9 @@ export enum ProtocolVersion {
|
|
|
5
5
|
export enum ClientMessageType {
|
|
6
6
|
Rpc = 10,
|
|
7
7
|
RpcAbort = 11,
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
Ping = 13,
|
|
10
|
+
Pong = 14,
|
|
9
11
|
|
|
10
12
|
ClientStreamPush = 20,
|
|
11
13
|
ClientStreamEnd = 21,
|
|
@@ -24,6 +26,9 @@ export enum ServerMessageType {
|
|
|
24
26
|
RpcStreamEnd = 13,
|
|
25
27
|
RpcStreamAbort = 14,
|
|
26
28
|
|
|
29
|
+
Pong = 15,
|
|
30
|
+
Ping = 16,
|
|
31
|
+
|
|
27
32
|
ServerStreamPush = 20,
|
|
28
33
|
ServerStreamEnd = 21,
|
|
29
34
|
ServerStreamAbort = 22,
|