@nmtjs/protocol 0.15.0-beta.9 → 0.15.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/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 +62 -31
- 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 +37 -20
- package/dist/server/versions/v1.js +19 -7
- package/dist/server/versions/v1.js.map +1 -1
- package/package.json +27 -17
- 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/src/server/stream.ts
CHANGED
|
@@ -28,6 +28,8 @@ export class ProtocolClientStream extends PassThrough {
|
|
|
28
28
|
export class ProtocolServerStream extends PassThrough {
|
|
29
29
|
public readonly id: number
|
|
30
30
|
public readonly metadata: ProtocolBlobMetadata
|
|
31
|
+
readonly #source: Readable
|
|
32
|
+
#piped = false
|
|
31
33
|
|
|
32
34
|
constructor(id: number, blob: ProtocolBlob) {
|
|
33
35
|
let readable: Readable
|
|
@@ -43,9 +45,28 @@ export class ProtocolServerStream extends PassThrough {
|
|
|
43
45
|
super()
|
|
44
46
|
|
|
45
47
|
this.pause()
|
|
46
|
-
readable
|
|
48
|
+
this.#source = readable
|
|
49
|
+
this.#source.on('error', (error) => {
|
|
50
|
+
this.destroy(error)
|
|
51
|
+
})
|
|
47
52
|
|
|
48
53
|
this.id = id
|
|
49
54
|
this.metadata = blob.metadata
|
|
50
55
|
}
|
|
56
|
+
|
|
57
|
+
override resume(): this {
|
|
58
|
+
if (!this.#piped) {
|
|
59
|
+
this.#piped = true
|
|
60
|
+
this.#source.pipe(this)
|
|
61
|
+
}
|
|
62
|
+
return super.resume()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override destroy(error?: Error | null) {
|
|
66
|
+
if (!this.#piped) {
|
|
67
|
+
this.#piped = true
|
|
68
|
+
}
|
|
69
|
+
this.#source.destroy?.(error ?? undefined)
|
|
70
|
+
return super.destroy(error ?? undefined)
|
|
71
|
+
}
|
|
51
72
|
}
|
package/src/server/utils.ts
CHANGED
|
@@ -11,12 +11,12 @@ export const getFormat = (
|
|
|
11
11
|
format: ProtocolFormats,
|
|
12
12
|
{ accept, contentType }: ResolveFormatParams,
|
|
13
13
|
) => {
|
|
14
|
-
const encoder =
|
|
15
|
-
if (!encoder)
|
|
16
|
-
throw new UnsupportedContentTypeError('Unsupported Content type')
|
|
14
|
+
const encoder = accept ? format.supportsEncoder(accept) : undefined
|
|
15
|
+
if (!encoder) throw new UnsupportedAcceptTypeError('Unsupported Accept type')
|
|
17
16
|
|
|
18
|
-
const decoder =
|
|
19
|
-
if (!decoder)
|
|
17
|
+
const decoder = contentType ? format.supportsDecoder(contentType) : undefined
|
|
18
|
+
if (!decoder)
|
|
19
|
+
throw new UnsupportedContentTypeError('Unsupported Content type')
|
|
20
20
|
|
|
21
21
|
return { encoder, decoder }
|
|
22
22
|
}
|
|
@@ -38,10 +38,6 @@ export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
|
38
38
|
|
|
39
39
|
return { type: messageType, rpc: { callId, procedure, payload } }
|
|
40
40
|
}
|
|
41
|
-
case ClientMessageType.RpcPull: {
|
|
42
|
-
const callId = messagePayload.readUInt32LE(0)
|
|
43
|
-
return { type: messageType, callId }
|
|
44
|
-
}
|
|
45
41
|
case ClientMessageType.RpcAbort: {
|
|
46
42
|
const callId = messagePayload.readUInt32LE(0)
|
|
47
43
|
const reasonPayload = messagePayload.subarray(MessageByteLength.CallId)
|
|
@@ -49,6 +45,14 @@ export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
|
49
45
|
reasonPayload.byteLength > 0 ? decodeText(reasonPayload) : undefined
|
|
50
46
|
return { type: messageType, callId, reason }
|
|
51
47
|
}
|
|
48
|
+
case ClientMessageType.Ping: {
|
|
49
|
+
const nonce = messagePayload.readUInt32LE(0)
|
|
50
|
+
return { type: messageType, nonce }
|
|
51
|
+
}
|
|
52
|
+
case ClientMessageType.Pong: {
|
|
53
|
+
const nonce = messagePayload.readUInt32LE(0)
|
|
54
|
+
return { type: messageType, nonce }
|
|
55
|
+
}
|
|
52
56
|
case ClientMessageType.ServerStreamAbort: {
|
|
53
57
|
const streamId = messagePayload.readUInt32LE(0)
|
|
54
58
|
const reasonPayload = messagePayload.subarray(
|
|
@@ -146,6 +150,22 @@ export class ProtocolVersion1 extends ProtocolVersionInterface {
|
|
|
146
150
|
reason ? encodeText(reason) : Buffer.alloc(0),
|
|
147
151
|
)
|
|
148
152
|
}
|
|
153
|
+
case ServerMessageType.Pong: {
|
|
154
|
+
const { nonce } =
|
|
155
|
+
payload as ServerMessageTypePayload[ServerMessageType.Pong]
|
|
156
|
+
return this.encode(
|
|
157
|
+
encodeNumber(messageType, 'Uint8'),
|
|
158
|
+
encodeNumber(nonce, 'Uint32'),
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
case ServerMessageType.Ping: {
|
|
162
|
+
const { nonce } =
|
|
163
|
+
payload as ServerMessageTypePayload[ServerMessageType.Ping]
|
|
164
|
+
return this.encode(
|
|
165
|
+
encodeNumber(messageType, 'Uint8'),
|
|
166
|
+
encodeNumber(nonce, 'Uint32'),
|
|
167
|
+
)
|
|
168
|
+
}
|
|
149
169
|
case ServerMessageType.ClientStreamPull: {
|
|
150
170
|
const { size, streamId } =
|
|
151
171
|
payload as ServerMessageTypePayload[ServerMessageType.ClientStreamPull]
|