@nmtjs/client 0.15.3 → 0.16.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/dist/client.d.ts +64 -0
- package/dist/client.js +97 -0
- package/dist/client.js.map +1 -0
- package/dist/clients/runtime.d.ts +6 -12
- package/dist/clients/runtime.js +58 -57
- package/dist/clients/runtime.js.map +1 -1
- package/dist/clients/static.d.ts +4 -9
- package/dist/clients/static.js +20 -20
- package/dist/clients/static.js.map +1 -1
- package/dist/core.d.ts +33 -83
- package/dist/core.js +305 -690
- package/dist/core.js.map +1 -1
- package/dist/events.d.ts +0 -1
- package/dist/events.js +74 -11
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/layers/ping.d.ts +6 -0
- package/dist/layers/ping.js +65 -0
- package/dist/layers/ping.js.map +1 -0
- package/dist/layers/rpc.d.ts +19 -0
- package/dist/layers/rpc.js +521 -0
- package/dist/layers/rpc.js.map +1 -0
- package/dist/layers/streams.d.ts +20 -0
- package/dist/layers/streams.js +194 -0
- package/dist/layers/streams.js.map +1 -0
- package/dist/plugins/browser.js +28 -9
- package/dist/plugins/browser.js.map +1 -1
- package/dist/plugins/heartbeat.js +10 -10
- package/dist/plugins/heartbeat.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +0 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/reconnect.js +11 -94
- package/dist/plugins/reconnect.js.map +1 -1
- package/dist/plugins/types.d.ts +27 -11
- package/dist/transport.d.ts +49 -31
- package/dist/types.d.ts +21 -5
- package/package.json +10 -10
- package/src/client.ts +216 -0
- package/src/clients/runtime.ts +93 -79
- package/src/clients/static.ts +46 -38
- package/src/core.ts +394 -901
- package/src/events.ts +113 -14
- package/src/index.ts +4 -0
- package/src/layers/ping.ts +99 -0
- package/src/layers/rpc.ts +725 -0
- package/src/layers/streams.ts +277 -0
- package/src/plugins/browser.ts +39 -9
- package/src/plugins/heartbeat.ts +10 -10
- package/src/plugins/index.ts +8 -1
- package/src/plugins/reconnect.ts +12 -119
- package/src/plugins/types.ts +30 -13
- package/src/transport.ts +75 -46
- package/src/types.ts +33 -8
package/src/transport.ts
CHANGED
|
@@ -5,59 +5,84 @@ import type {
|
|
|
5
5
|
} from '@nmtjs/protocol'
|
|
6
6
|
import type { BaseClientFormat } from '@nmtjs/protocol/client'
|
|
7
7
|
|
|
8
|
-
export type
|
|
9
|
-
signal?: AbortSignal
|
|
10
|
-
_stream_response?: boolean
|
|
11
|
-
}
|
|
8
|
+
export type ClientDisconnectReason = 'client' | 'server' | (string & {})
|
|
12
9
|
|
|
13
|
-
export interface
|
|
10
|
+
export interface TransportConnectParams {
|
|
14
11
|
auth?: string
|
|
15
12
|
application?: string
|
|
16
|
-
onMessage: (message: ArrayBufferView) =>
|
|
17
|
-
onConnect: () =>
|
|
18
|
-
onDisconnect: (reason:
|
|
13
|
+
onMessage: (message: ArrayBufferView) => void
|
|
14
|
+
onConnect: () => void
|
|
15
|
+
onDisconnect: (reason: ClientDisconnectReason) => void
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
export interface
|
|
22
|
-
|
|
18
|
+
export interface TransportSendOptions {
|
|
19
|
+
signal?: AbortSignal
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TransportCallContext {
|
|
23
|
+
contentType: string
|
|
23
24
|
auth?: string
|
|
24
25
|
application?: string
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
28
|
+
export interface TransportRpcParams {
|
|
29
|
+
callId: number
|
|
30
|
+
procedure: string
|
|
31
|
+
payload: ArrayBufferView
|
|
32
|
+
blob?: { source: ReadableStream; metadata: ProtocolBlobMetadata }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TransportCallOptions {
|
|
36
|
+
signal?: AbortSignal
|
|
37
|
+
streamResponse?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface TransportRpcResponse {
|
|
41
|
+
type: 'rpc'
|
|
42
|
+
result: ArrayBufferView
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface TransportRpcStreamResponse {
|
|
46
|
+
type: 'rpc_stream'
|
|
47
|
+
stream: ReadableStream<ArrayBufferView>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface TransportBlobResponse {
|
|
51
|
+
type: 'blob'
|
|
52
|
+
metadata: ProtocolBlobMetadata
|
|
53
|
+
source: ReadableStream<ArrayBufferView>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface TransportErrorResponse {
|
|
57
|
+
type: 'error'
|
|
58
|
+
error: ArrayBufferView
|
|
59
|
+
status?: number
|
|
60
|
+
statusText?: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type TransportCallResponse =
|
|
64
|
+
| TransportRpcResponse
|
|
65
|
+
| TransportRpcStreamResponse
|
|
66
|
+
| TransportBlobResponse
|
|
67
|
+
| TransportErrorResponse
|
|
68
|
+
|
|
69
|
+
export interface BidirectionalTransport {
|
|
70
|
+
type: ConnectionType.Bidirectional
|
|
71
|
+
connect(params: TransportConnectParams): Promise<void>
|
|
72
|
+
disconnect(): Promise<void>
|
|
73
|
+
send(message: ArrayBufferView, options: TransportSendOptions): Promise<void>
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface UnidirectionalTransport {
|
|
77
|
+
type: ConnectionType.Unidirectional
|
|
78
|
+
call(
|
|
79
|
+
context: TransportCallContext,
|
|
80
|
+
rpc: TransportRpcParams,
|
|
81
|
+
options: TransportCallOptions,
|
|
82
|
+
): Promise<TransportCallResponse>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type ClientTransport = BidirectionalTransport | UnidirectionalTransport
|
|
61
86
|
|
|
62
87
|
export interface ClientTransportParams {
|
|
63
88
|
protocol: ProtocolVersion
|
|
@@ -65,7 +90,11 @@ export interface ClientTransportParams {
|
|
|
65
90
|
}
|
|
66
91
|
|
|
67
92
|
export type ClientTransportFactory<
|
|
68
|
-
|
|
93
|
+
Transport extends ClientTransport = ClientTransport,
|
|
69
94
|
Options = unknown,
|
|
70
|
-
Transport extends ClientTransport<Type> = ClientTransport<Type>,
|
|
71
95
|
> = (params: ClientTransportParams, options: Options) => Transport
|
|
96
|
+
|
|
97
|
+
export type ClientTransportMessageOptions = TransportSendOptions
|
|
98
|
+
export type ClientTransportStartParams = TransportConnectParams
|
|
99
|
+
export type ClientTransportRpcParams = TransportCallContext
|
|
100
|
+
export type ClientCallResponse = TransportCallResponse
|
package/src/types.ts
CHANGED
|
@@ -3,24 +3,30 @@ import type { TAnyProcedureContract, TAnyRouterContract } from '@nmtjs/contract'
|
|
|
3
3
|
import type { ProtocolBlobInterface } from '@nmtjs/protocol'
|
|
4
4
|
import type {
|
|
5
5
|
ProtocolError,
|
|
6
|
-
|
|
6
|
+
ProtocolServerBlobConsumer,
|
|
7
7
|
} from '@nmtjs/protocol/client'
|
|
8
8
|
import type { BaseTypeAny, PlainType, t } from '@nmtjs/type'
|
|
9
9
|
|
|
10
10
|
export const ResolvedType: unique symbol = Symbol('ResolvedType')
|
|
11
11
|
export type ResolvedType = typeof ResolvedType
|
|
12
12
|
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export type RpcCallOptions = { timeout?: number; signal?: AbortSignal }
|
|
14
|
+
|
|
15
|
+
export type StreamCallOptions = RpcCallOptions & { autoReconnect?: boolean }
|
|
16
|
+
|
|
17
|
+
export type ClientCallOptions = StreamCallOptions & {
|
|
16
18
|
/**
|
|
17
19
|
* @internal
|
|
18
20
|
*/
|
|
19
21
|
_stream_response?: boolean
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
export type BlobSubscriptionOptions = { signal?: AbortSignal }
|
|
25
|
+
|
|
26
|
+
export type StreamSubscriptionOptions = Partial<StreamCallOptions>
|
|
27
|
+
|
|
22
28
|
export type ClientOutputType<T> = T extends ProtocolBlobInterface
|
|
23
|
-
?
|
|
29
|
+
? ProtocolServerBlobConsumer
|
|
24
30
|
: T extends { [PlainType]?: true }
|
|
25
31
|
? { [K in keyof Omit<T, PlainType>]: ClientOutputType<T[K]> }
|
|
26
32
|
: T
|
|
@@ -99,10 +105,29 @@ export type ClientCaller<
|
|
|
99
105
|
SafeCall extends boolean,
|
|
100
106
|
> = (
|
|
101
107
|
...args: Procedure['input'] extends t.NeverType
|
|
102
|
-
? [
|
|
108
|
+
? [
|
|
109
|
+
data?: undefined,
|
|
110
|
+
options?: Partial<
|
|
111
|
+
Procedure['stream'] extends true ? StreamCallOptions : RpcCallOptions
|
|
112
|
+
>,
|
|
113
|
+
]
|
|
103
114
|
: undefined extends t.infer.encode.input<Procedure['contract']['input']>
|
|
104
|
-
? [
|
|
105
|
-
|
|
115
|
+
? [
|
|
116
|
+
data?: Procedure['input'],
|
|
117
|
+
options?: Partial<
|
|
118
|
+
Procedure['stream'] extends true
|
|
119
|
+
? StreamCallOptions
|
|
120
|
+
: RpcCallOptions
|
|
121
|
+
>,
|
|
122
|
+
]
|
|
123
|
+
: [
|
|
124
|
+
data: Procedure['input'],
|
|
125
|
+
options?: Partial<
|
|
126
|
+
Procedure['stream'] extends true
|
|
127
|
+
? StreamCallOptions
|
|
128
|
+
: RpcCallOptions
|
|
129
|
+
>,
|
|
130
|
+
]
|
|
106
131
|
) => SafeCall extends true
|
|
107
132
|
? Promise<OneOf<[{ result: Procedure['output'] }, { error: ProtocolError }]>>
|
|
108
133
|
: Promise<Procedure['output']>
|