@nmtjs/gateway 0.15.0-beta.3 → 0.15.0-beta.4
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/package.json +11 -10
- package/src/api.ts +26 -0
- package/src/connections.ts +54 -0
- package/src/enums.ts +15 -0
- package/src/gateway.ts +698 -0
- package/src/index.ts +9 -0
- package/src/injectables.ts +88 -0
- package/src/rpcs.ts +90 -0
- package/src/streams.ts +408 -0
- package/src/transport.ts +95 -0
- package/src/types.ts +24 -0
package/package.json
CHANGED
|
@@ -6,26 +6,27 @@
|
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"hookable": "6.0.0-rc.1",
|
|
9
|
-
"@nmtjs/common": "0.15.0-beta.
|
|
10
|
-
"@nmtjs/
|
|
11
|
-
"@nmtjs/
|
|
12
|
-
"@nmtjs/protocol": "0.15.0-beta.
|
|
9
|
+
"@nmtjs/common": "0.15.0-beta.4",
|
|
10
|
+
"@nmtjs/type": "0.15.0-beta.4",
|
|
11
|
+
"@nmtjs/core": "0.15.0-beta.4",
|
|
12
|
+
"@nmtjs/protocol": "0.15.0-beta.4"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@nmtjs/common": "0.15.0-beta.
|
|
16
|
-
"@nmtjs/type": "0.15.0-beta.
|
|
17
|
-
"@nmtjs/
|
|
18
|
-
"@nmtjs/
|
|
15
|
+
"@nmtjs/common": "0.15.0-beta.4",
|
|
16
|
+
"@nmtjs/type": "0.15.0-beta.4",
|
|
17
|
+
"@nmtjs/core": "0.15.0-beta.4",
|
|
18
|
+
"@nmtjs/protocol": "0.15.0-beta.4"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@nmtjs/_tests": "0.15.0-beta.
|
|
21
|
+
"@nmtjs/_tests": "0.15.0-beta.4"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
|
+
"src",
|
|
25
26
|
"LICENSE.md",
|
|
26
27
|
"README.md"
|
|
27
28
|
],
|
|
28
|
-
"version": "0.15.0-beta.
|
|
29
|
+
"version": "0.15.0-beta.4",
|
|
29
30
|
"scripts": {
|
|
30
31
|
"clean-build": "rm -rf ./dist",
|
|
31
32
|
"build": "tsc --declaration --sourcemap",
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Container, MetadataStore } from '@nmtjs/core'
|
|
2
|
+
|
|
3
|
+
import type { GatewayConnection } from './connections.ts'
|
|
4
|
+
|
|
5
|
+
export type GatewayApiCallOptions = {
|
|
6
|
+
connection: GatewayConnection
|
|
7
|
+
procedure: string
|
|
8
|
+
container: Container
|
|
9
|
+
payload: any
|
|
10
|
+
signal: AbortSignal
|
|
11
|
+
metadata?: (store: MetadataStore) => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type GatewayApiCallResult = unknown
|
|
15
|
+
|
|
16
|
+
export interface GatewayApi {
|
|
17
|
+
call(options: GatewayApiCallOptions): Promise<GatewayApiCallResult>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isAsyncIterable(
|
|
21
|
+
value: GatewayApiCallResult,
|
|
22
|
+
): value is AsyncIterable<unknown> | Iterable<unknown> {
|
|
23
|
+
return Boolean(
|
|
24
|
+
value && typeof value === 'object' && Symbol.asyncIterator in value,
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Container } from '@nmtjs/core'
|
|
2
|
+
import type { ConnectionType } from '@nmtjs/protocol'
|
|
3
|
+
import type {
|
|
4
|
+
BaseServerDecoder,
|
|
5
|
+
BaseServerEncoder,
|
|
6
|
+
ProtocolVersionInterface,
|
|
7
|
+
} from '@nmtjs/protocol/server'
|
|
8
|
+
import { MAX_UINT32, throwError } from '@nmtjs/common'
|
|
9
|
+
|
|
10
|
+
export interface GatewayConnection {
|
|
11
|
+
readonly id: string
|
|
12
|
+
readonly type: ConnectionType
|
|
13
|
+
readonly transport: string
|
|
14
|
+
readonly protocol: ProtocolVersionInterface
|
|
15
|
+
readonly identity: string
|
|
16
|
+
readonly container: Container
|
|
17
|
+
readonly encoder: BaseServerEncoder
|
|
18
|
+
readonly decoder: BaseServerDecoder
|
|
19
|
+
readonly abortController: AbortController
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class ConnectionManager {
|
|
23
|
+
readonly connections = new Map<string, GatewayConnection>()
|
|
24
|
+
readonly streamIds = new Map<string, number>()
|
|
25
|
+
|
|
26
|
+
add(connection: GatewayConnection) {
|
|
27
|
+
this.connections.set(connection.id, connection)
|
|
28
|
+
this.streamIds.set(connection.id, 0)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get(id: string) {
|
|
32
|
+
return this.connections.get(id) ?? throwError('Connection not found')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
has(id: string) {
|
|
36
|
+
return this.connections.has(id)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
remove(id: string) {
|
|
40
|
+
this.connections.delete(id)
|
|
41
|
+
this.streamIds.delete(id)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getAll() {
|
|
45
|
+
return this.connections.values()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getStreamId(connectionId: string) {
|
|
49
|
+
let streamId = this.streamIds.get(connectionId)!
|
|
50
|
+
if (streamId >= MAX_UINT32) streamId = 0
|
|
51
|
+
this.streamIds.set(connectionId, streamId + 1)
|
|
52
|
+
return streamId
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/enums.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export enum GatewayHook {
|
|
2
|
+
Connect = 'Connect',
|
|
3
|
+
Disconnect = 'Disconnect',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export enum ProxyableTransportType {
|
|
7
|
+
WebSocket = 'WebSocket',
|
|
8
|
+
HTTP = 'HTTP',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum StreamTimeout {
|
|
12
|
+
Pull = 'Pull',
|
|
13
|
+
Consume = 'Consume',
|
|
14
|
+
Finish = 'Finish',
|
|
15
|
+
}
|