@litert/televoke 0.4.6 → 1.0.0-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/CHANGES.md +6 -0
- package/README.md +13 -8
- package/lib/client/Client.decl.d.ts +47 -0
- package/lib/client/Client.decl.d.ts.map +1 -0
- package/lib/client/Client.decl.js +18 -0
- package/lib/client/Client.decl.js.map +1 -0
- package/lib/client/JsonApiClient.impl.d.ts +28 -0
- package/lib/client/JsonApiClient.impl.d.ts.map +1 -0
- package/lib/client/JsonApiClient.impl.js +169 -0
- package/lib/client/JsonApiClient.impl.js.map +1 -0
- package/lib/client/LegacyHttpClient.impl.d.ts +62 -0
- package/lib/client/LegacyHttpClient.impl.d.ts.map +1 -0
- package/lib/client/LegacyHttpClient.impl.js +163 -0
- package/lib/client/LegacyHttpClient.impl.js.map +1 -0
- package/lib/client/index.d.ts +19 -0
- package/lib/client/index.d.ts.map +1 -0
- package/lib/client/index.js +35 -0
- package/lib/client/index.js.map +1 -0
- package/lib/index.d.ts +18 -20
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -20
- package/lib/index.js.map +1 -1
- package/lib/server/LegacyServerChannel.impl.d.ts +38 -0
- package/lib/server/LegacyServerChannel.impl.d.ts.map +1 -0
- package/lib/server/LegacyServerChannel.impl.js +51 -0
- package/lib/server/LegacyServerChannel.impl.js.map +1 -0
- package/lib/server/Server.decl.d.ts +81 -0
- package/lib/server/Server.decl.d.ts.map +1 -0
- package/lib/server/Server.decl.js +18 -0
- package/lib/server/Server.decl.js.map +1 -0
- package/lib/server/Server.impl.d.ts +33 -0
- package/lib/server/Server.impl.d.ts.map +1 -0
- package/lib/server/Server.impl.js +58 -0
- package/lib/server/Server.impl.js.map +1 -0
- package/lib/server/ServerChannel.d.ts +20 -0
- package/lib/server/ServerChannel.d.ts.map +1 -0
- package/lib/server/ServerChannel.js +23 -0
- package/lib/server/ServerChannel.js.map +1 -0
- package/lib/server/SimpleJsonApiRouter.d.ts +28 -0
- package/lib/server/SimpleJsonApiRouter.d.ts.map +1 -0
- package/lib/server/SimpleJsonApiRouter.js +92 -0
- package/lib/server/SimpleJsonApiRouter.js.map +1 -0
- package/lib/server/index.d.ts +19 -0
- package/lib/server/index.d.ts.map +1 -0
- package/lib/server/index.js +35 -0
- package/lib/server/index.js.map +1 -0
- package/lib/shared/BinaryStream.d.ts +32 -0
- package/lib/shared/BinaryStream.d.ts.map +1 -0
- package/lib/shared/BinaryStream.js +93 -0
- package/lib/shared/BinaryStream.js.map +1 -0
- package/lib/shared/BinaryStreamManager.d.ts +52 -0
- package/lib/shared/BinaryStreamManager.d.ts.map +1 -0
- package/lib/shared/BinaryStreamManager.js +105 -0
- package/lib/shared/BinaryStreamManager.js.map +1 -0
- package/lib/shared/Channel.impl.d.ts +79 -0
- package/lib/shared/Channel.impl.d.ts.map +1 -0
- package/lib/shared/Channel.impl.js +433 -0
- package/lib/shared/Channel.impl.js.map +1 -0
- package/lib/shared/Constants.d.ts +32 -0
- package/lib/shared/Constants.d.ts.map +1 -0
- package/lib/shared/Constants.js +35 -0
- package/lib/shared/Constants.js.map +1 -0
- package/lib/shared/Encodings/index.d.ts +18 -0
- package/lib/shared/Encodings/index.d.ts.map +1 -0
- package/lib/shared/Encodings/index.js +21 -0
- package/lib/shared/Encodings/index.js.map +1 -0
- package/lib/shared/Encodings/v1/EncoderV1.d.ts +22 -0
- package/lib/shared/Encodings/v1/EncoderV1.d.ts.map +1 -0
- package/lib/shared/Encodings/v1/EncoderV1.js +47 -0
- package/lib/shared/Encodings/v1/EncoderV1.js.map +1 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.d.ts +78 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.d.ts.map +1 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.js +53 -0
- package/lib/shared/Encodings/v1/Protocol.v1.decls.js.map +1 -0
- package/lib/shared/Encodings/v1/index.d.ts +18 -0
- package/lib/shared/Encodings/v1/index.d.ts.map +1 -0
- package/lib/shared/Encodings/v1/index.js +34 -0
- package/lib/shared/Encodings/v1/index.js.map +1 -0
- package/lib/shared/Encodings/v2/Constants.v2.d.ts +29 -0
- package/lib/shared/Encodings/v2/Constants.v2.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/Constants.v2.js +34 -0
- package/lib/shared/Encodings/v2/Constants.v2.js.map +1 -0
- package/lib/shared/Encodings/v2/DecoderV2.d.ts +27 -0
- package/lib/shared/Encodings/v2/DecoderV2.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/DecoderV2.js +279 -0
- package/lib/shared/Encodings/v2/DecoderV2.js.map +1 -0
- package/lib/shared/Encodings/v2/EncoderV2.d.ts +21 -0
- package/lib/shared/Encodings/v2/EncoderV2.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/EncoderV2.js +176 -0
- package/lib/shared/Encodings/v2/EncoderV2.js.map +1 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.d.ts +95 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.js +18 -0
- package/lib/shared/Encodings/v2/Encoding.v2.decl.js.map +1 -0
- package/lib/shared/Encodings/v2/index.d.ts +20 -0
- package/lib/shared/Encodings/v2/index.d.ts.map +1 -0
- package/lib/shared/Encodings/v2/index.js +35 -0
- package/lib/shared/Encodings/v2/index.js.map +1 -0
- package/lib/shared/Errors.d.ts +60 -0
- package/lib/shared/Errors.d.ts.map +1 -0
- package/lib/shared/Errors.js +75 -0
- package/lib/shared/Errors.js.map +1 -0
- package/lib/shared/Shared.decl.d.ts +296 -0
- package/lib/shared/Shared.decl.d.ts.map +1 -0
- package/lib/shared/Shared.decl.js +18 -0
- package/lib/shared/Shared.decl.js.map +1 -0
- package/lib/shared/Utils.d.ts +25 -0
- package/lib/shared/Utils.d.ts.map +1 -0
- package/lib/shared/Utils.js +46 -0
- package/lib/shared/Utils.js.map +1 -0
- package/lib/shared/index.d.ts +23 -0
- package/lib/shared/index.d.ts.map +1 -0
- package/lib/shared/index.js +39 -0
- package/lib/shared/index.js.map +1 -0
- package/lib/transporters/Transporter.decl.d.ts +90 -0
- package/lib/transporters/Transporter.decl.d.ts.map +1 -0
- package/lib/transporters/Transporter.decl.js +18 -0
- package/lib/transporters/Transporter.decl.js.map +1 -0
- package/lib/transporters/http-listener/AbstractHttpListener.d.ts +32 -0
- package/lib/transporters/http-listener/AbstractHttpListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/AbstractHttpListener.js +46 -0
- package/lib/transporters/http-listener/AbstractHttpListener.js.map +1 -0
- package/lib/transporters/http-listener/Http.Decl.d.ts +95 -0
- package/lib/transporters/http-listener/Http.Decl.d.ts.map +1 -0
- package/lib/transporters/http-listener/Http.Decl.js +52 -0
- package/lib/transporters/http-listener/Http.Decl.js.map +1 -0
- package/lib/transporters/http-listener/HttpListener.d.ts +18 -0
- package/lib/transporters/http-listener/HttpListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/HttpListener.js +73 -0
- package/lib/transporters/http-listener/HttpListener.js.map +1 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.d.ts +18 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.js +72 -0
- package/lib/transporters/http-listener/HttpUnixSocketListener.js.map +1 -0
- package/lib/transporters/http-listener/HttpsListener.d.ts +18 -0
- package/lib/transporters/http-listener/HttpsListener.d.ts.map +1 -0
- package/lib/transporters/http-listener/HttpsListener.js +73 -0
- package/lib/transporters/http-listener/HttpsListener.js.map +1 -0
- package/lib/transporters/http-listener/index.d.ts +20 -0
- package/lib/transporters/http-listener/index.d.ts.map +1 -0
- package/lib/transporters/http-listener/index.js +36 -0
- package/lib/transporters/http-listener/index.js.map +1 -0
- package/lib/transporters/index.d.ts +17 -0
- package/lib/transporters/index.d.ts.map +1 -0
- package/lib/transporters/index.js +18 -0
- package/lib/transporters/index.js.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.d.ts +24 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.d.ts.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.js +167 -0
- package/lib/transporters/legacy-http/LegacyHttp.Server.js.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.d.ts +28 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.d.ts.map +1 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.js +55 -0
- package/lib/transporters/legacy-http/LegacyHttp.Transporter.js.map +1 -0
- package/lib/transporters/legacy-http/index.d.ts +18 -0
- package/lib/transporters/legacy-http/index.d.ts.map +1 -0
- package/lib/transporters/legacy-http/index.js +34 -0
- package/lib/transporters/legacy-http/index.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.d.ts +19 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.js +33 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Client.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.d.ts +21 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.js +64 -0
- package/lib/transporters/lwdfx/LwDFX.Tcp.Server.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.d.ts +19 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.js +33 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Client.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.d.ts +21 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.js +64 -0
- package/lib/transporters/lwdfx/LwDFX.Tls.Server.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.d.ts +34 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.js +78 -0
- package/lib/transporters/lwdfx/LwDFX.Transporter.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.d.ts +19 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.js +33 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.d.ts +21 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.js +64 -0
- package/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.js.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.decl.d.ts +18 -0
- package/lib/transporters/lwdfx/LwDFX.decl.d.ts.map +1 -0
- package/lib/transporters/lwdfx/LwDFX.decl.js +18 -0
- package/lib/transporters/lwdfx/LwDFX.decl.js.map +1 -0
- package/lib/transporters/lwdfx/index.d.ts +23 -0
- package/lib/transporters/lwdfx/index.d.ts.map +1 -0
- package/lib/transporters/lwdfx/index.js +39 -0
- package/lib/transporters/lwdfx/index.js.map +1 -0
- package/lib/transporters/memory/Memory.Impl.d.ts +43 -0
- package/lib/transporters/memory/Memory.Impl.d.ts.map +1 -0
- package/lib/transporters/memory/Memory.Impl.js +227 -0
- package/lib/transporters/memory/Memory.Impl.js.map +1 -0
- package/lib/transporters/memory/index.d.ts +17 -0
- package/lib/transporters/memory/index.d.ts.map +1 -0
- package/lib/transporters/memory/index.js +33 -0
- package/lib/transporters/memory/index.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.Client.d.ts +20 -0
- package/lib/transporters/websocket/WebSocket.Client.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.Client.js +68 -0
- package/lib/transporters/websocket/WebSocket.Client.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.Server.d.ts +25 -0
- package/lib/transporters/websocket/WebSocket.Server.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.Server.js +87 -0
- package/lib/transporters/websocket/WebSocket.Server.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.Transporter.d.ts +34 -0
- package/lib/transporters/websocket/WebSocket.Transporter.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.Transporter.js +106 -0
- package/lib/transporters/websocket/WebSocket.Transporter.js.map +1 -0
- package/lib/transporters/websocket/WebSocket.decl.d.ts +19 -0
- package/lib/transporters/websocket/WebSocket.decl.d.ts.map +1 -0
- package/lib/transporters/websocket/WebSocket.decl.js +22 -0
- package/lib/transporters/websocket/WebSocket.decl.js.map +1 -0
- package/lib/transporters/websocket/index.d.ts +19 -0
- package/lib/transporters/websocket/index.d.ts.map +1 -0
- package/lib/transporters/websocket/index.js +35 -0
- package/lib/transporters/websocket/index.js.map +1 -0
- package/package.json +12 -12
- package/src/lib/client/Client.decl.ts +61 -0
- package/src/lib/client/JsonApiClient.impl.ts +258 -0
- package/src/lib/client/LegacyHttpClient.impl.ts +278 -0
- package/src/lib/client/index.ts +19 -0
- package/src/lib/index.ts +18 -20
- package/src/lib/server/LegacyServerChannel.impl.ts +71 -0
- package/src/lib/server/Server.decl.ts +109 -0
- package/src/lib/server/Server.impl.ts +90 -0
- package/src/lib/server/ServerChannel.ts +20 -0
- package/src/lib/server/SimpleJsonApiRouter.ts +135 -0
- package/src/lib/server/index.ts +19 -0
- package/src/lib/shared/BinaryStream.ts +131 -0
- package/src/lib/shared/BinaryStreamManager.ts +142 -0
- package/src/lib/shared/Channel.impl.ts +641 -0
- package/src/lib/shared/Constants.ts +35 -0
- package/src/lib/shared/Encodings/index.ts +18 -0
- package/src/lib/shared/Encodings/v1/EncoderV1.ts +66 -0
- package/src/lib/shared/Encodings/v1/Protocol.v1.decls.ts +96 -0
- package/src/lib/shared/Encodings/v1/index.ts +18 -0
- package/src/lib/shared/Encodings/v2/Constants.v2.ts +31 -0
- package/src/lib/shared/Encodings/v2/DecoderV2.ts +404 -0
- package/src/lib/shared/Encodings/v2/EncoderV2.ts +283 -0
- package/src/lib/shared/Encodings/v2/Encoding.v2.decl.ts +133 -0
- package/src/lib/shared/Encodings/v2/index.ts +20 -0
- package/src/lib/shared/Errors.ts +94 -0
- package/src/lib/shared/Shared.decl.ts +347 -0
- package/src/lib/shared/Utils.ts +51 -0
- package/src/lib/shared/index.ts +23 -0
- package/src/lib/transporters/Transporter.decl.ts +117 -0
- package/src/lib/transporters/http-listener/AbstractHttpListener.ts +57 -0
- package/src/lib/transporters/http-listener/Http.Decl.ts +141 -0
- package/src/lib/transporters/http-listener/HttpListener.ts +102 -0
- package/src/lib/transporters/http-listener/HttpUnixSocketListener.ts +97 -0
- package/src/lib/transporters/http-listener/HttpsListener.ts +102 -0
- package/src/lib/transporters/http-listener/index.ts +20 -0
- package/src/lib/transporters/index.ts +17 -0
- package/src/lib/transporters/legacy-http/LegacyHttp.Server.ts +262 -0
- package/src/lib/transporters/legacy-http/LegacyHttp.Transporter.ts +66 -0
- package/src/lib/transporters/legacy-http/index.ts +18 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tcp.Client.ts +34 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tcp.Server.ts +94 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tls.Client.ts +34 -0
- package/src/lib/transporters/lwdfx/LwDFX.Tls.Server.ts +94 -0
- package/src/lib/transporters/lwdfx/LwDFX.Transporter.ts +100 -0
- package/src/lib/transporters/lwdfx/LwDFX.UnixSocket.Client.ts +34 -0
- package/src/lib/transporters/lwdfx/LwDFX.UnixSocket.Server.ts +94 -0
- package/src/lib/transporters/lwdfx/LwDFX.decl.ts +19 -0
- package/src/lib/transporters/lwdfx/index.ts +23 -0
- package/src/lib/transporters/memory/Memory.Impl.ts +363 -0
- package/src/lib/transporters/memory/index.ts +17 -0
- package/src/lib/transporters/websocket/WebSocket.Client.ts +76 -0
- package/src/lib/transporters/websocket/WebSocket.Server.ts +118 -0
- package/src/lib/transporters/websocket/WebSocket.Transporter.ts +132 -0
- package/src/lib/transporters/websocket/WebSocket.decl.ts +21 -0
- package/src/lib/transporters/websocket/index.ts +19 -0
- package/lib/Client/BuiltInRIDGenerator.d.ts +0 -4
- package/lib/Client/BuiltInRIDGenerator.d.ts.map +0 -1
- package/lib/Client/BuiltInRIDGenerator.js +0 -18
- package/lib/Client/BuiltInRIDGenerator.js.map +0 -1
- package/lib/Client/Common.d.ts +0 -47
- package/lib/Client/Common.d.ts.map +0 -1
- package/lib/Client/Common.js +0 -18
- package/lib/Client/Common.js.map +0 -1
- package/lib/Client/Errors.d.ts +0 -26
- package/lib/Client/Errors.d.ts.map +0 -1
- package/lib/Client/Errors.js +0 -80
- package/lib/Client/Errors.js.map +0 -1
- package/lib/Client/HttpClient.d.ts +0 -37
- package/lib/Client/HttpClient.d.ts.map +0 -1
- package/lib/Client/HttpClient.js +0 -148
- package/lib/Client/HttpClient.js.map +0 -1
- package/lib/Client/HttpsClient.d.ts +0 -40
- package/lib/Client/HttpsClient.d.ts.map +0 -1
- package/lib/Client/HttpsClient.js +0 -144
- package/lib/Client/HttpsClient.js.map +0 -1
- package/lib/Client/TCPClient.d.ts +0 -34
- package/lib/Client/TCPClient.d.ts.map +0 -1
- package/lib/Client/TCPClient.js +0 -271
- package/lib/Client/TCPClient.js.map +0 -1
- package/lib/Client/TLSClient.d.ts +0 -34
- package/lib/Client/TLSClient.d.ts.map +0 -1
- package/lib/Client/TLSClient.js +0 -265
- package/lib/Client/TLSClient.js.map +0 -1
- package/lib/Client/index.d.ts +0 -23
- package/lib/Client/index.d.ts.map +0 -1
- package/lib/Client/index.js +0 -39
- package/lib/Client/index.js.map +0 -1
- package/lib/Common/API.d.ts +0 -19
- package/lib/Common/API.d.ts.map +0 -1
- package/lib/Common/API.js +0 -18
- package/lib/Common/API.js.map +0 -1
- package/lib/Common/Encoding.d.ts +0 -32
- package/lib/Common/Encoding.d.ts.map +0 -1
- package/lib/Common/Encoding.js +0 -20
- package/lib/Common/Encoding.js.map +0 -1
- package/lib/Common/Request.d.ts +0 -23
- package/lib/Common/Request.d.ts.map +0 -1
- package/lib/Common/Request.js +0 -18
- package/lib/Common/Request.js.map +0 -1
- package/lib/Common/Response.d.ts +0 -60
- package/lib/Common/Response.d.ts.map +0 -1
- package/lib/Common/Response.js +0 -42
- package/lib/Common/Response.js.map +0 -1
- package/lib/Common/index.d.ts +0 -20
- package/lib/Common/index.d.ts.map +0 -1
- package/lib/Common/index.js +0 -36
- package/lib/Common/index.js.map +0 -1
- package/lib/Encoder/Decoder.d.ts +0 -18
- package/lib/Encoder/Decoder.d.ts.map +0 -1
- package/lib/Encoder/Decoder.js +0 -136
- package/lib/Encoder/Decoder.js.map +0 -1
- package/lib/Encoder/Encoder.d.ts +0 -18
- package/lib/Encoder/Encoder.d.ts.map +0 -1
- package/lib/Encoder/Encoder.js +0 -35
- package/lib/Encoder/Encoder.js.map +0 -1
- package/lib/Encoder/Errors.d.ts +0 -17
- package/lib/Encoder/Errors.d.ts.map +0 -1
- package/lib/Encoder/Errors.js +0 -26
- package/lib/Encoder/Errors.js.map +0 -1
- package/lib/Errors.d.ts +0 -20
- package/lib/Errors.d.ts.map +0 -1
- package/lib/Errors.js +0 -40
- package/lib/Errors.js.map +0 -1
- package/lib/Server/Common/Gateway.d.ts +0 -26
- package/lib/Server/Common/Gateway.d.ts.map +0 -1
- package/lib/Server/Common/Gateway.js +0 -18
- package/lib/Server/Common/Gateway.js.map +0 -1
- package/lib/Server/Common/Request.d.ts +0 -21
- package/lib/Server/Common/Request.d.ts.map +0 -1
- package/lib/Server/Common/Request.js +0 -18
- package/lib/Server/Common/Request.js.map +0 -1
- package/lib/Server/Common/Router.d.ts +0 -41
- package/lib/Server/Common/Router.d.ts.map +0 -1
- package/lib/Server/Common/Router.js +0 -18
- package/lib/Server/Common/Router.js.map +0 -1
- package/lib/Server/Common/Server.d.ts +0 -57
- package/lib/Server/Common/Server.d.ts.map +0 -1
- package/lib/Server/Common/Server.js +0 -18
- package/lib/Server/Common/Server.js.map +0 -1
- package/lib/Server/Common/index.d.ts +0 -20
- package/lib/Server/Common/index.d.ts.map +0 -1
- package/lib/Server/Common/index.js +0 -36
- package/lib/Server/Common/index.js.map +0 -1
- package/lib/Server/Errors.d.ts +0 -25
- package/lib/Server/Errors.d.ts.map +0 -1
- package/lib/Server/Errors.js +0 -74
- package/lib/Server/Errors.js.map +0 -1
- package/lib/Server/Gateways/Http.d.ts +0 -18
- package/lib/Server/Gateways/Http.d.ts.map +0 -1
- package/lib/Server/Gateways/Http.js +0 -144
- package/lib/Server/Gateways/Http.js.map +0 -1
- package/lib/Server/Gateways/TCP.d.ts +0 -23
- package/lib/Server/Gateways/TCP.d.ts.map +0 -1
- package/lib/Server/Gateways/TCP.js +0 -146
- package/lib/Server/Gateways/TCP.js.map +0 -1
- package/lib/Server/Server.d.ts +0 -18
- package/lib/Server/Server.d.ts.map +0 -1
- package/lib/Server/Server.js +0 -200
- package/lib/Server/Server.js.map +0 -1
- package/lib/Server/SimpleRouter.d.ts +0 -41
- package/lib/Server/SimpleRouter.d.ts.map +0 -1
- package/lib/Server/SimpleRouter.js +0 -54
- package/lib/Server/SimpleRouter.js.map +0 -1
- package/lib/Server/index.d.ts +0 -22
- package/lib/Server/index.d.ts.map +0 -1
- package/lib/Server/index.js +0 -38
- package/lib/Server/index.js.map +0 -1
- package/src/lib/Client/BuiltInRIDGenerator.ts +0 -21
- package/src/lib/Client/Common.ts +0 -63
- package/src/lib/Client/Errors.ts +0 -87
- package/src/lib/Client/HttpClient.ts +0 -232
- package/src/lib/Client/HttpsClient.ts +0 -238
- package/src/lib/Client/TCPClient.ts +0 -420
- package/src/lib/Client/TLSClient.ts +0 -422
- package/src/lib/Client/index.ts +0 -23
- package/src/lib/Common/API.ts +0 -20
- package/src/lib/Common/Encoding.ts +0 -42
- package/src/lib/Common/Request.ts +0 -28
- package/src/lib/Common/Response.ts +0 -67
- package/src/lib/Common/index.ts +0 -20
- package/src/lib/Encoder/Decoder.ts +0 -206
- package/src/lib/Encoder/Encoder.ts +0 -41
- package/src/lib/Encoder/Errors.ts +0 -24
- package/src/lib/Errors.ts +0 -40
- package/src/lib/Server/Common/Gateway.ts +0 -37
- package/src/lib/Server/Common/Request.ts +0 -24
- package/src/lib/Server/Common/Router.ts +0 -52
- package/src/lib/Server/Common/Server.ts +0 -68
- package/src/lib/Server/Common/index.ts +0 -20
- package/src/lib/Server/Errors.ts +0 -80
- package/src/lib/Server/Gateways/Http.ts +0 -203
- package/src/lib/Server/Gateways/TCP.ts +0 -221
- package/src/lib/Server/Server.ts +0 -268
- package/src/lib/Server/SimpleRouter.ts +0 -95
- package/src/lib/Server/index.ts +0 -22
package/lib/Client/HttpClient.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright 2021 Angus.Fenying <fenying@litert.org>
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.createHttpClient = void 0;
|
|
19
|
-
const $Http = require("http");
|
|
20
|
-
const GE = require("../Errors");
|
|
21
|
-
const G = require("../Common");
|
|
22
|
-
const E = require("./Errors");
|
|
23
|
-
const observable_1 = require("@litert/observable");
|
|
24
|
-
class HttpClient extends observable_1.Events.EventEmitter {
|
|
25
|
-
constructor(_host, _port, _ridGenerator, _path = '/', _timeout = 30000, _apiNameWrapper) {
|
|
26
|
-
super();
|
|
27
|
-
this._host = _host;
|
|
28
|
-
this._port = _port;
|
|
29
|
-
this._ridGenerator = _ridGenerator;
|
|
30
|
-
this._path = _path;
|
|
31
|
-
this._timeout = _timeout;
|
|
32
|
-
this._apiNameWrapper = _apiNameWrapper;
|
|
33
|
-
this._agent = new $Http.Agent({
|
|
34
|
-
maxSockets: 0,
|
|
35
|
-
keepAlive: true,
|
|
36
|
-
keepAliveMsecs: 30000
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
invoke(api, ...args) {
|
|
40
|
-
return this._call(api, false, args);
|
|
41
|
-
}
|
|
42
|
-
call(api, ...args) {
|
|
43
|
-
return this._call(api, true, args);
|
|
44
|
-
}
|
|
45
|
-
_call(api, returnRaw, args) {
|
|
46
|
-
const rid = this._ridGenerator();
|
|
47
|
-
const CST = Date.now();
|
|
48
|
-
const content = JSON.stringify({
|
|
49
|
-
ttl: this._timeout,
|
|
50
|
-
rid,
|
|
51
|
-
cst: CST,
|
|
52
|
-
args,
|
|
53
|
-
api: this._apiNameWrapper ? this._apiNameWrapper(api) : api
|
|
54
|
-
});
|
|
55
|
-
return new Promise((resolve, reject) => {
|
|
56
|
-
const length = Buffer.byteLength(content);
|
|
57
|
-
if (length > G.MAX_PACKET_SIZE) {
|
|
58
|
-
reject(new GE.E_PACKET_TOO_LARGE());
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const req = $Http.request({
|
|
62
|
-
port: this._port,
|
|
63
|
-
host: this._host,
|
|
64
|
-
path: this._path,
|
|
65
|
-
agent: this._agent,
|
|
66
|
-
method: 'POST',
|
|
67
|
-
headers: {
|
|
68
|
-
'content-length': Buffer.byteLength(content),
|
|
69
|
-
'x-tv-ver': 1
|
|
70
|
-
},
|
|
71
|
-
timeout: this._timeout
|
|
72
|
-
}, (resp) => {
|
|
73
|
-
if (!resp.headers['content-length']) {
|
|
74
|
-
reject(new E.E_INVALID_RESPONSE());
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const length = parseInt(resp.headers['content-length']);
|
|
78
|
-
if (!Number.isSafeInteger(length) || length > G.MAX_PACKET_SIZE) { // Maximum request packet is 64MB
|
|
79
|
-
reject(new GE.E_PACKET_TOO_LARGE());
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const buf = Buffer.allocUnsafe(length);
|
|
83
|
-
let offset = 0;
|
|
84
|
-
resp.on('data', (chunk) => {
|
|
85
|
-
const index = offset;
|
|
86
|
-
offset += chunk.byteLength;
|
|
87
|
-
if (offset > length) {
|
|
88
|
-
resp.removeAllListeners('end');
|
|
89
|
-
resp.removeAllListeners('data');
|
|
90
|
-
resp.destroy();
|
|
91
|
-
reject(new GE.E_INVALID_PACKET());
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
chunk.copy(buf, index);
|
|
95
|
-
}).on('end', () => {
|
|
96
|
-
let rawData;
|
|
97
|
-
try {
|
|
98
|
-
rawData = JSON.parse(buf);
|
|
99
|
-
}
|
|
100
|
-
catch (_a) {
|
|
101
|
-
reject(new GE.E_INVALID_PACKET());
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const data = rawData;
|
|
105
|
-
data.cst = CST;
|
|
106
|
-
data.crt = Date.now();
|
|
107
|
-
switch (data.code) {
|
|
108
|
-
case G.EResponseCode.OK:
|
|
109
|
-
resolve(returnRaw ? data : data.body);
|
|
110
|
-
break;
|
|
111
|
-
case G.EResponseCode.SYSTEM_ERROR:
|
|
112
|
-
reject(new E.E_SERVER_INTERNAL_ERROR(Object.assign({ api }, data)));
|
|
113
|
-
break;
|
|
114
|
-
case G.EResponseCode.FAILURE:
|
|
115
|
-
reject(new E.E_SERVER_LOGIC_FAILURE(Object.assign({ api }, data)));
|
|
116
|
-
break;
|
|
117
|
-
case G.EResponseCode.API_NOT_FOUND:
|
|
118
|
-
reject(new E.E_API_NOT_FOUND(Object.assign({ api }, data)));
|
|
119
|
-
break;
|
|
120
|
-
default:
|
|
121
|
-
reject(new E.E_SERVER_UNKNOWN_ERROR(Object.assign({ api }, data)));
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
req.once('timeout', () => {
|
|
127
|
-
reject(new E.E_REQUEST_TIMEOUT({
|
|
128
|
-
metadata: { api, requestId: rid, time: Date.now(), details: null }
|
|
129
|
-
}));
|
|
130
|
-
});
|
|
131
|
-
req.once('error', reject);
|
|
132
|
-
req.end(content);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
connect() {
|
|
136
|
-
return Promise.resolve();
|
|
137
|
-
}
|
|
138
|
-
close() {
|
|
139
|
-
this._agent.destroy();
|
|
140
|
-
return Promise.resolve();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function createHttpClient(opts) {
|
|
144
|
-
var _a;
|
|
145
|
-
return new HttpClient(opts.host, (_a = opts.port) !== null && _a !== void 0 ? _a : 80, opts.ridGenerator, opts.path, opts.timeout, opts.apiNameWrapper);
|
|
146
|
-
}
|
|
147
|
-
exports.createHttpClient = createHttpClient;
|
|
148
|
-
//# sourceMappingURL=HttpClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/lib/Client/HttpClient.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,8BAA8B;AAE9B,gCAAgC;AAChC,+BAA+B;AAC/B,8BAA8B;AAC9B,mDAA4C;AAE5C,MAAM,UAAW,SAAQ,mBAAM,CAAC,YAAyC;IAMrE,YACqB,KAAa,EACb,KAAa,EACb,aAA8B,EAC9B,QAAgB,GAAG,EACnB,WAAmB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<fenying@litert.org>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
/// <reference types="node" />
|
|
17
|
-
import * as $Https from 'https';
|
|
18
|
-
import * as C from './Common';
|
|
19
|
-
import * as G from '../Common';
|
|
20
|
-
export interface IHttpsClientOptions {
|
|
21
|
-
host: string;
|
|
22
|
-
/**
|
|
23
|
-
* The port of HTTPS server.
|
|
24
|
-
*
|
|
25
|
-
* @default 443
|
|
26
|
-
*/
|
|
27
|
-
port?: number;
|
|
28
|
-
/**
|
|
29
|
-
* The path to the RPC entry.
|
|
30
|
-
*
|
|
31
|
-
* @default '/'
|
|
32
|
-
*/
|
|
33
|
-
path?: string;
|
|
34
|
-
ridGenerator: C.IRIDGenerator;
|
|
35
|
-
timeout?: number;
|
|
36
|
-
apiNameWrapper?: (name: string) => string;
|
|
37
|
-
tlsAgentOptions?: $Https.AgentOptions;
|
|
38
|
-
}
|
|
39
|
-
export declare function createHttpsClient<TAPIs extends G.IServiceAPIs>(opts: IHttpsClientOptions): C.IClient<TAPIs>;
|
|
40
|
-
//# sourceMappingURL=HttpsClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HttpsClient.d.ts","sourceRoot":"","sources":["../../src/lib/Client/HttpsClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;AAEH,OAAO,KAAK,MAAM,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,KAAK,CAAC,MAAM,WAAW,CAAC;AAoL/B,MAAM,WAAW,mBAAmB;IAEhC,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,YAAY,EAAE,CAAC,CAAC,aAAa,CAAC;IAE9B,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAE1C,eAAe,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC;CACzC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,EAAE,IAAI,EAAE,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAW3G"}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright 2021 Angus.Fenying <fenying@litert.org>
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.createHttpsClient = void 0;
|
|
19
|
-
const $Https = require("https");
|
|
20
|
-
const GE = require("../Errors");
|
|
21
|
-
const G = require("../Common");
|
|
22
|
-
const E = require("./Errors");
|
|
23
|
-
const observable_1 = require("@litert/observable");
|
|
24
|
-
class HttpsClient extends observable_1.Events.EventEmitter {
|
|
25
|
-
constructor(_host, _port, _ridGenerator, _path = '', _timeout = 30000, _apiNameWrapper, tlsAgentOptions) {
|
|
26
|
-
super();
|
|
27
|
-
this._host = _host;
|
|
28
|
-
this._port = _port;
|
|
29
|
-
this._ridGenerator = _ridGenerator;
|
|
30
|
-
this._path = _path;
|
|
31
|
-
this._timeout = _timeout;
|
|
32
|
-
this._apiNameWrapper = _apiNameWrapper;
|
|
33
|
-
this._agent = new $Https.Agent(Object.assign({ maxSockets: 0, keepAlive: true, keepAliveMsecs: 30000 }, tlsAgentOptions));
|
|
34
|
-
}
|
|
35
|
-
invoke(api, ...args) {
|
|
36
|
-
return this._call(api, false, args);
|
|
37
|
-
}
|
|
38
|
-
call(api, ...args) {
|
|
39
|
-
return this._call(api, true, args);
|
|
40
|
-
}
|
|
41
|
-
_call(api, returnRaw, args) {
|
|
42
|
-
const rid = this._ridGenerator();
|
|
43
|
-
const CST = Date.now();
|
|
44
|
-
const content = JSON.stringify({
|
|
45
|
-
ttl: this._timeout,
|
|
46
|
-
rid,
|
|
47
|
-
cst: CST,
|
|
48
|
-
args,
|
|
49
|
-
api: this._apiNameWrapper ? this._apiNameWrapper(api) : api
|
|
50
|
-
});
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
const length = Buffer.byteLength(content);
|
|
53
|
-
if (length > G.MAX_PACKET_SIZE) {
|
|
54
|
-
reject(new GE.E_PACKET_TOO_LARGE());
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const req = $Https.request({
|
|
58
|
-
port: this._port,
|
|
59
|
-
host: this._host,
|
|
60
|
-
path: this._path,
|
|
61
|
-
agent: this._agent,
|
|
62
|
-
method: 'POST',
|
|
63
|
-
headers: {
|
|
64
|
-
'content-length': Buffer.byteLength(content),
|
|
65
|
-
'x-tv-ver': 1
|
|
66
|
-
},
|
|
67
|
-
timeout: this._timeout
|
|
68
|
-
}, (resp) => {
|
|
69
|
-
if (!resp.headers['content-length']) {
|
|
70
|
-
reject(new E.E_INVALID_RESPONSE());
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const length = parseInt(resp.headers['content-length']);
|
|
74
|
-
if (!Number.isSafeInteger(length) || length > G.MAX_PACKET_SIZE) { // Maximum request packet is 64MB
|
|
75
|
-
reject(new GE.E_PACKET_TOO_LARGE());
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const buf = Buffer.allocUnsafe(length);
|
|
79
|
-
let offset = 0;
|
|
80
|
-
resp.on('data', (chunk) => {
|
|
81
|
-
const index = offset;
|
|
82
|
-
offset += chunk.byteLength;
|
|
83
|
-
if (offset > length) {
|
|
84
|
-
resp.removeAllListeners('end');
|
|
85
|
-
resp.removeAllListeners('data');
|
|
86
|
-
resp.destroy();
|
|
87
|
-
reject(new GE.E_INVALID_PACKET());
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
chunk.copy(buf, index);
|
|
91
|
-
}).on('end', () => {
|
|
92
|
-
let rawData;
|
|
93
|
-
try {
|
|
94
|
-
rawData = JSON.parse(buf);
|
|
95
|
-
}
|
|
96
|
-
catch (_a) {
|
|
97
|
-
reject(new GE.E_INVALID_PACKET());
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const data = rawData;
|
|
101
|
-
data.cst = CST;
|
|
102
|
-
data.crt = Date.now();
|
|
103
|
-
switch (data.code) {
|
|
104
|
-
case G.EResponseCode.OK:
|
|
105
|
-
resolve(returnRaw ? data : data.body);
|
|
106
|
-
break;
|
|
107
|
-
case G.EResponseCode.SYSTEM_ERROR:
|
|
108
|
-
reject(new E.E_SERVER_INTERNAL_ERROR(Object.assign({ api }, data)));
|
|
109
|
-
break;
|
|
110
|
-
case G.EResponseCode.FAILURE:
|
|
111
|
-
reject(new E.E_SERVER_LOGIC_FAILURE(Object.assign({ api }, data)));
|
|
112
|
-
break;
|
|
113
|
-
case G.EResponseCode.API_NOT_FOUND:
|
|
114
|
-
reject(new E.E_API_NOT_FOUND(Object.assign({ api }, data)));
|
|
115
|
-
break;
|
|
116
|
-
default:
|
|
117
|
-
reject(new E.E_SERVER_UNKNOWN_ERROR(Object.assign({ api }, data)));
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
req.once('timeout', () => {
|
|
123
|
-
reject(new E.E_REQUEST_TIMEOUT({
|
|
124
|
-
metadata: { api, requestId: rid, time: Date.now(), details: null }
|
|
125
|
-
}));
|
|
126
|
-
});
|
|
127
|
-
req.once('error', reject);
|
|
128
|
-
req.end(content);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
connect() {
|
|
132
|
-
return Promise.resolve();
|
|
133
|
-
}
|
|
134
|
-
close() {
|
|
135
|
-
this._agent.destroy();
|
|
136
|
-
return Promise.resolve();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
function createHttpsClient(opts) {
|
|
140
|
-
var _a;
|
|
141
|
-
return new HttpsClient(opts.host, (_a = opts.port) !== null && _a !== void 0 ? _a : 443, opts.ridGenerator, opts.path, opts.timeout, opts.apiNameWrapper, opts.tlsAgentOptions);
|
|
142
|
-
}
|
|
143
|
-
exports.createHttpsClient = createHttpsClient;
|
|
144
|
-
//# sourceMappingURL=HttpsClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HttpsClient.js","sourceRoot":"","sources":["../../src/lib/Client/HttpsClient.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,gCAAgC;AAEhC,gCAAgC;AAChC,+BAA+B;AAC/B,8BAA8B;AAC9B,mDAA4C;AAE5C,MAAM,WAAY,SAAQ,mBAAM,CAAC,YAAyC;IAMtE,YACqB,KAAa,EACb,KAAa,EACb,aAA8B,EAC9B,QAAgB,EAAE,EAClB,WAAmB,KAA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**
|
|
2
|
-
* Copyright 2021 Angus.Fenying <fenying@litert.org>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import * as C from './Common';
|
|
17
|
-
import * as G from '../Common';
|
|
18
|
-
export interface ITCPClientOptions {
|
|
19
|
-
host: string;
|
|
20
|
-
/**
|
|
21
|
-
* The port of TCP RPC server.
|
|
22
|
-
*/
|
|
23
|
-
port: number;
|
|
24
|
-
ridGenerator: C.IRIDGenerator;
|
|
25
|
-
timeout?: number;
|
|
26
|
-
apiNameWrapper?: (name: string) => string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Create a client of TCP-base televoke/1 protocol.
|
|
30
|
-
*
|
|
31
|
-
* @deprecated This legacy TCP-based televoke/1 protocol is no longer maintained, and will be removed in v2.0.0
|
|
32
|
-
*/
|
|
33
|
-
export declare function createTCPClient<TAPIs extends G.IServiceAPIs>(opts: ITCPClientOptions): C.IClient<TAPIs>;
|
|
34
|
-
//# sourceMappingURL=TCPClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TCPClient.d.ts","sourceRoot":"","sources":["../../src/lib/Client/TCPClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,CAAC,MAAM,WAAW,CAAC;AAmX/B,MAAM,WAAW,iBAAiB;IAE9B,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,EAAE,CAAC,CAAC,aAAa,CAAC;IAE9B,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CAC7C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,EAAE,IAAI,EAAE,iBAAiB,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CASvG"}
|
package/lib/Client/TCPClient.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright 2021 Angus.Fenying <fenying@litert.org>
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.createTCPClient = void 0;
|
|
19
|
-
const $Net = require("net");
|
|
20
|
-
const G = require("../Common");
|
|
21
|
-
const observable_1 = require("@litert/observable");
|
|
22
|
-
const E = require("./Errors");
|
|
23
|
-
const Decoder_1 = require("../Encoder/Decoder");
|
|
24
|
-
const Encoder_1 = require("../Encoder/Encoder");
|
|
25
|
-
var EStatus;
|
|
26
|
-
(function (EStatus) {
|
|
27
|
-
EStatus[EStatus["IDLE"] = 0] = "IDLE";
|
|
28
|
-
EStatus[EStatus["CONNECTING"] = 1] = "CONNECTING";
|
|
29
|
-
EStatus[EStatus["CLOSING"] = 2] = "CLOSING";
|
|
30
|
-
EStatus[EStatus["WORKING"] = 3] = "WORKING";
|
|
31
|
-
})(EStatus || (EStatus = {}));
|
|
32
|
-
class TCPClient extends observable_1.Events.EventEmitter {
|
|
33
|
-
constructor(_host, _port, _ridGenerator, _timeout = 30000, _apiNameWrapper) {
|
|
34
|
-
super();
|
|
35
|
-
this._host = _host;
|
|
36
|
-
this._port = _port;
|
|
37
|
-
this._ridGenerator = _ridGenerator;
|
|
38
|
-
this._timeout = _timeout;
|
|
39
|
-
this._apiNameWrapper = _apiNameWrapper;
|
|
40
|
-
this._status = EStatus.IDLE;
|
|
41
|
-
this._clientId = TCPClient._$clientCounter++;
|
|
42
|
-
this._sent = {};
|
|
43
|
-
this._sentQty = 0;
|
|
44
|
-
this._sending = {};
|
|
45
|
-
this._sendingQty = 0;
|
|
46
|
-
this._encoder = (0, Encoder_1.createEncoder)();
|
|
47
|
-
this._connPrId = `litert:televoke:tcp:client:${this._clientId}:connect`;
|
|
48
|
-
this._closePrId = `litert:televoke:tcp:client:${this._clientId}:close`;
|
|
49
|
-
}
|
|
50
|
-
invoke(api, ...args) {
|
|
51
|
-
return this._call(api, false, args);
|
|
52
|
-
}
|
|
53
|
-
call(api, ...args) {
|
|
54
|
-
return this._call(api, true, args);
|
|
55
|
-
}
|
|
56
|
-
_call(api, returnRaw, args) {
|
|
57
|
-
const rid = this._ridGenerator();
|
|
58
|
-
let pr;
|
|
59
|
-
switch (this._status) {
|
|
60
|
-
case EStatus.IDLE:
|
|
61
|
-
return Promise.reject(new E.E_CONN_NOT_READY());
|
|
62
|
-
case EStatus.WORKING: {
|
|
63
|
-
const NOW = Date.now();
|
|
64
|
-
this._encoder.encode(this._socket, {
|
|
65
|
-
ttl: this._timeout,
|
|
66
|
-
rid,
|
|
67
|
-
cst: NOW,
|
|
68
|
-
args,
|
|
69
|
-
api: this._apiNameWrapper ? this._apiNameWrapper(api) : api
|
|
70
|
-
});
|
|
71
|
-
this._sentQty++;
|
|
72
|
-
this._sent[rid] = {
|
|
73
|
-
api,
|
|
74
|
-
cst: NOW,
|
|
75
|
-
returnRaw,
|
|
76
|
-
pr: pr = TCPClient._$promises.createPromise(),
|
|
77
|
-
timer: this._timeout > 0 ? setTimeout(() => {
|
|
78
|
-
const req = this._sent[rid];
|
|
79
|
-
if (req) {
|
|
80
|
-
delete this._sent[rid];
|
|
81
|
-
this._sentQty--;
|
|
82
|
-
req.pr.reject(new E.E_REQUEST_TIMEOUT({
|
|
83
|
-
metadata: { api: req.api, requestId: rid, time: req.cst, details: null }
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
if (this._status === EStatus.CLOSING && !this._sentQty) {
|
|
87
|
-
this._socket.destroy();
|
|
88
|
-
this._status = EStatus.IDLE;
|
|
89
|
-
}
|
|
90
|
-
}, this._timeout) : undefined
|
|
91
|
-
};
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case EStatus.CONNECTING: {
|
|
95
|
-
const NOW = Date.now();
|
|
96
|
-
this._sendingQty++;
|
|
97
|
-
this._sending[rid] = {
|
|
98
|
-
api,
|
|
99
|
-
pr: pr = TCPClient._$promises.createPromise(),
|
|
100
|
-
cst: NOW,
|
|
101
|
-
returnRaw,
|
|
102
|
-
packet: {
|
|
103
|
-
ttl: this._timeout,
|
|
104
|
-
rid,
|
|
105
|
-
cst: NOW,
|
|
106
|
-
args,
|
|
107
|
-
api: this._apiNameWrapper ? this._apiNameWrapper(api) : api
|
|
108
|
-
},
|
|
109
|
-
timer: this._timeout > 0 ? setTimeout(() => {
|
|
110
|
-
let req = this._sent[rid];
|
|
111
|
-
if (req) {
|
|
112
|
-
delete this._sent[rid];
|
|
113
|
-
this._sentQty--;
|
|
114
|
-
req.pr.reject(new E.E_REQUEST_TIMEOUT({
|
|
115
|
-
metadata: { api: req.api, requestId: rid, time: req.cst, details: null }
|
|
116
|
-
}));
|
|
117
|
-
if (this._status === EStatus.CLOSING && !this._sentQty) {
|
|
118
|
-
this._socket.destroy();
|
|
119
|
-
this._status = EStatus.IDLE;
|
|
120
|
-
}
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
req = this._sending[rid];
|
|
124
|
-
if (req) {
|
|
125
|
-
delete this._sending[rid];
|
|
126
|
-
this._sendingQty--;
|
|
127
|
-
req.pr.reject(new E.E_REQUEST_TIMEOUT({
|
|
128
|
-
metadata: { api: req.api, requestId: rid, time: req.cst, details: null }
|
|
129
|
-
}));
|
|
130
|
-
if (this._status === EStatus.CLOSING && !this._sentQty) {
|
|
131
|
-
this._socket.destroy();
|
|
132
|
-
this._status = EStatus.IDLE;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}, this._timeout) : undefined
|
|
136
|
-
};
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
case EStatus.CLOSING:
|
|
140
|
-
throw new E.E_CONN_CLOSING();
|
|
141
|
-
}
|
|
142
|
-
return pr.promise;
|
|
143
|
-
}
|
|
144
|
-
connect() {
|
|
145
|
-
switch (this._status) {
|
|
146
|
-
case EStatus.WORKING:
|
|
147
|
-
return Promise.resolve();
|
|
148
|
-
case EStatus.CONNECTING:
|
|
149
|
-
return TCPClient._$promises.findPromise(this._connPrId).promise;
|
|
150
|
-
case EStatus.CLOSING:
|
|
151
|
-
this._status = EStatus.WORKING;
|
|
152
|
-
break;
|
|
153
|
-
case EStatus.IDLE:
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
this._socket = $Net.connect({
|
|
157
|
-
host: this._host,
|
|
158
|
-
port: this._port
|
|
159
|
-
});
|
|
160
|
-
const pr = TCPClient._$promises.createPromise({ id: this._connPrId });
|
|
161
|
-
this._socket.once('connect', () => {
|
|
162
|
-
this._status = EStatus.WORKING;
|
|
163
|
-
this._socket.removeAllListeners('error');
|
|
164
|
-
const decoder = (0, Decoder_1.createDecoder)();
|
|
165
|
-
decoder.onLogicError = (e) => this.emit('error', e);
|
|
166
|
-
decoder.onProtocolError = (e) => this.emit('error', e);
|
|
167
|
-
decoder.onData = (rawData) => {
|
|
168
|
-
const data = rawData;
|
|
169
|
-
const req = this._sent[data.rid];
|
|
170
|
-
if (!req) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
data.cst = req.cst;
|
|
174
|
-
data.crt = Date.now();
|
|
175
|
-
this._sentQty--;
|
|
176
|
-
delete this._sent[data.rid];
|
|
177
|
-
if (req.timer) {
|
|
178
|
-
clearTimeout(req.timer);
|
|
179
|
-
}
|
|
180
|
-
if (this._status === EStatus.CLOSING && !this._sentQty) {
|
|
181
|
-
this._socket.end();
|
|
182
|
-
this._status = EStatus.IDLE;
|
|
183
|
-
}
|
|
184
|
-
switch (data.code) {
|
|
185
|
-
case G.EResponseCode.OK:
|
|
186
|
-
req.pr.resolve(req.returnRaw ? data : data.body);
|
|
187
|
-
break;
|
|
188
|
-
case G.EResponseCode.SYSTEM_ERROR:
|
|
189
|
-
req.pr.reject(new E.E_SERVER_INTERNAL_ERROR(Object.assign({ api: req.api }, data)));
|
|
190
|
-
break;
|
|
191
|
-
case G.EResponseCode.FAILURE:
|
|
192
|
-
req.pr.reject(new E.E_SERVER_LOGIC_FAILURE(Object.assign({ api: req.api }, data)));
|
|
193
|
-
break;
|
|
194
|
-
case G.EResponseCode.API_NOT_FOUND:
|
|
195
|
-
req.pr.reject(new E.E_API_NOT_FOUND(Object.assign({ api: req.api }, data)));
|
|
196
|
-
break;
|
|
197
|
-
default:
|
|
198
|
-
req.pr.reject(new E.E_SERVER_UNKNOWN_ERROR(Object.assign({ api: req.api }, data)));
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
this._socket.on('data', decoder.decode.bind(decoder)).on('end', () => {
|
|
203
|
-
if (this._sentQty) {
|
|
204
|
-
const ls = this._sent;
|
|
205
|
-
this._sent = {};
|
|
206
|
-
for (const rid in ls) {
|
|
207
|
-
this._sent[rid].pr.reject(new E.E_CONN_LOST());
|
|
208
|
-
}
|
|
209
|
-
this._sentQty = 0;
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
if (this._sendingQty) {
|
|
213
|
-
for (const rid in this._sending) {
|
|
214
|
-
const req = this._sending[rid];
|
|
215
|
-
this._encoder.encode(this._socket, req.packet);
|
|
216
|
-
this._sent[rid] = req;
|
|
217
|
-
this._sentQty++;
|
|
218
|
-
delete req.packet;
|
|
219
|
-
}
|
|
220
|
-
this._sending = {};
|
|
221
|
-
this._sendingQty = 0;
|
|
222
|
-
}
|
|
223
|
-
pr.resolve();
|
|
224
|
-
}).once('error', (e) => {
|
|
225
|
-
this._socket = undefined;
|
|
226
|
-
pr.reject(e);
|
|
227
|
-
});
|
|
228
|
-
return pr.promise;
|
|
229
|
-
}
|
|
230
|
-
close() {
|
|
231
|
-
switch (this._status) {
|
|
232
|
-
case EStatus.IDLE:
|
|
233
|
-
return Promise.resolve();
|
|
234
|
-
case EStatus.CLOSING:
|
|
235
|
-
return TCPClient._$promises.findPromise(this._closePrId).promise;
|
|
236
|
-
case EStatus.WORKING:
|
|
237
|
-
break;
|
|
238
|
-
case EStatus.CONNECTING:
|
|
239
|
-
TCPClient._$promises.findPromise(this._connPrId).reject(new E.E_OPERATION_ABORTED());
|
|
240
|
-
}
|
|
241
|
-
if (this._sentQty) {
|
|
242
|
-
this._status = EStatus.CLOSING;
|
|
243
|
-
return TCPClient._$promises.createPromise({ id: this._closePrId }).promise;
|
|
244
|
-
}
|
|
245
|
-
if (this._sendingQty) {
|
|
246
|
-
for (const rid in this._sending) {
|
|
247
|
-
const req = this._sending[rid];
|
|
248
|
-
req.pr.reject(new E.E_CONN_LOST({
|
|
249
|
-
metadata: { api: req.api, requestId: rid, time: Date.now(), details: null }
|
|
250
|
-
}));
|
|
251
|
-
}
|
|
252
|
-
this._sending = {};
|
|
253
|
-
}
|
|
254
|
-
this._socket.destroy();
|
|
255
|
-
this._socket = undefined;
|
|
256
|
-
this._status = EStatus.IDLE;
|
|
257
|
-
return Promise.resolve();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
TCPClient._$promises = observable_1.Promises.getGlobalFactory();
|
|
261
|
-
TCPClient._$clientCounter = 0;
|
|
262
|
-
/**
|
|
263
|
-
* Create a client of TCP-base televoke/1 protocol.
|
|
264
|
-
*
|
|
265
|
-
* @deprecated This legacy TCP-based televoke/1 protocol is no longer maintained, and will be removed in v2.0.0
|
|
266
|
-
*/
|
|
267
|
-
function createTCPClient(opts) {
|
|
268
|
-
return new TCPClient(opts.host, opts.port, opts.ridGenerator, opts.timeout, opts.apiNameWrapper);
|
|
269
|
-
}
|
|
270
|
-
exports.createTCPClient = createTCPClient;
|
|
271
|
-
//# sourceMappingURL=TCPClient.js.map
|