@nmtjs/protocol 0.6.0 → 0.6.2
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/events.js +3 -16
- package/dist/client/events.js.map +1 -1
- package/dist/client/protocol.js +68 -57
- package/dist/client/protocol.js.map +1 -1
- package/dist/client/stream.js +2 -3
- package/dist/client/stream.js.map +1 -1
- package/dist/server/api.js.map +1 -1
- package/dist/server/connection.js +1 -0
- package/dist/server/connection.js.map +1 -1
- package/dist/server/protocol.js +26 -8
- package/dist/server/protocol.js.map +1 -1
- package/lib/client/events.ts +4 -16
- package/lib/client/protocol.ts +108 -68
- package/lib/client/stream.ts +12 -5
- package/lib/server/api.ts +1 -2
- package/lib/server/connection.ts +1 -12
- package/lib/server/protocol.ts +30 -7
- package/package.json +4 -4
package/lib/server/protocol.ts
CHANGED
|
@@ -100,7 +100,8 @@ export class ProtocolConnections {
|
|
|
100
100
|
|
|
101
101
|
this.#collection.delete(connectionId)
|
|
102
102
|
|
|
103
|
-
const { calls, serverStreams, clientStreams, container } =
|
|
103
|
+
const { calls, serverStreams, clientStreams, rpcStreams, container } =
|
|
104
|
+
context
|
|
104
105
|
|
|
105
106
|
for (const call of calls.values()) {
|
|
106
107
|
call.reject(new Error('Connection closed'))
|
|
@@ -114,6 +115,10 @@ export class ProtocolConnections {
|
|
|
114
115
|
stream.destroy(new Error('Connection closed'))
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
for (const stream of rpcStreams.values()) {
|
|
119
|
+
stream.abort(new Error('Connection closed'))
|
|
120
|
+
}
|
|
121
|
+
|
|
117
122
|
try {
|
|
118
123
|
await container.dispose()
|
|
119
124
|
} catch (error) {
|
|
@@ -229,7 +234,7 @@ export class Protocol {
|
|
|
229
234
|
this.serverStreams = new ProtocolServerStreams(this.connections)
|
|
230
235
|
}
|
|
231
236
|
|
|
232
|
-
async
|
|
237
|
+
async rpc(
|
|
233
238
|
connectionId: string,
|
|
234
239
|
rpc: ProtocolRPC,
|
|
235
240
|
params: { signal?: AbortSignal } = {},
|
|
@@ -314,11 +319,14 @@ export class Protocol {
|
|
|
314
319
|
responseEncoded,
|
|
315
320
|
)
|
|
316
321
|
try {
|
|
322
|
+
const ab = new AbortController()
|
|
323
|
+
context.rpcStreams.set(callId, ab)
|
|
317
324
|
const iterable =
|
|
318
325
|
typeof response.iterable === 'function'
|
|
319
326
|
? response.iterable()
|
|
320
327
|
: response.iterable
|
|
321
328
|
for await (const chunk of iterable) {
|
|
329
|
+
if (ab.signal.aborted) break
|
|
322
330
|
const chunkEncoded = format.encoder.encode(chunk)
|
|
323
331
|
transport.send(
|
|
324
332
|
connection,
|
|
@@ -333,6 +341,9 @@ export class Protocol {
|
|
|
333
341
|
ServerMessageType.RpcStreamAbort,
|
|
334
342
|
callIdEncoded,
|
|
335
343
|
)
|
|
344
|
+
} finally {
|
|
345
|
+
context.rpcStreams.delete(callId)
|
|
346
|
+
response.onFinish && defer(response.onFinish)
|
|
336
347
|
}
|
|
337
348
|
} else {
|
|
338
349
|
transport.send(
|
|
@@ -377,7 +388,7 @@ export class Protocol {
|
|
|
377
388
|
}
|
|
378
389
|
}
|
|
379
390
|
|
|
380
|
-
async
|
|
391
|
+
async rpcRaw(
|
|
381
392
|
connectionId: string,
|
|
382
393
|
buffer: ArrayBuffer,
|
|
383
394
|
params: { signal?: AbortSignal } = {},
|
|
@@ -402,18 +413,30 @@ export class Protocol {
|
|
|
402
413
|
},
|
|
403
414
|
})
|
|
404
415
|
|
|
405
|
-
return await this.
|
|
416
|
+
return await this.rpc(connectionId, rpc, params)
|
|
406
417
|
}
|
|
407
418
|
|
|
408
|
-
|
|
419
|
+
rpcAbort(connectionId: string, callId: number) {
|
|
409
420
|
const { context } = this.connections.get(connectionId)
|
|
410
421
|
const call = context.calls.get(callId) ?? throwError('Call not found')
|
|
411
422
|
call.abort()
|
|
412
423
|
}
|
|
413
424
|
|
|
414
|
-
|
|
425
|
+
rpcAbortRaw(connectionId: string, buffer: ArrayBuffer) {
|
|
426
|
+
const callId = decodeNumber(buffer, 'Uint32')
|
|
427
|
+
return this.rpcAbort(connectionId, callId)
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
rpcStreamAbort(connectionId: string, callId: number) {
|
|
431
|
+
const { context } = this.connections.get(connectionId)
|
|
432
|
+
const ab =
|
|
433
|
+
context.rpcStreams.get(callId) ?? throwError('Call stream not found')
|
|
434
|
+
ab.abort()
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
rpcStreamAbortRaw(connectionId: string, buffer: ArrayBuffer) {
|
|
415
438
|
const callId = decodeNumber(buffer, 'Uint32')
|
|
416
|
-
return this.
|
|
439
|
+
return this.rpcStreamAbort(connectionId, callId)
|
|
417
440
|
}
|
|
418
441
|
|
|
419
442
|
notify(connectionId: string, event, payload) {
|
package/package.json
CHANGED
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@nmtjs/type": "0.6.
|
|
23
|
-
"@nmtjs/core": "0.6.
|
|
24
|
-
"@nmtjs/common": "0.6.
|
|
22
|
+
"@nmtjs/type": "0.6.2",
|
|
23
|
+
"@nmtjs/core": "0.6.2",
|
|
24
|
+
"@nmtjs/common": "0.6.2"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"index.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"LICENSE.md",
|
|
32
32
|
"README.md"
|
|
33
33
|
],
|
|
34
|
-
"version": "0.6.
|
|
34
|
+
"version": "0.6.2",
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "neemata-build --root=./lib './**/*.ts'",
|
|
37
37
|
"type-check": "tsc --noEmit"
|