@celljs/rpc 4.3.0 → 4.4.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/README.md +117 -1
- package/cell.schema.json +100 -0
- package/cell.yml +12 -8
- package/esm/common/annotation/index.d.ts +2 -0
- package/esm/common/annotation/index.js +2 -0
- package/esm/common/annotation/index.js.map +1 -1
- package/esm/common/annotation/rpc-client.d.ts +7 -0
- package/esm/common/annotation/rpc-client.js +18 -0
- package/esm/common/annotation/rpc-client.js.map +1 -0
- package/esm/common/annotation/rpc-protocol.d.ts +7 -0
- package/esm/common/annotation/rpc-protocol.js +2 -0
- package/esm/common/annotation/rpc-protocol.js.map +1 -0
- package/esm/common/annotation/rpc.d.ts +4 -0
- package/esm/common/annotation/rpc.js +14 -18
- package/esm/common/annotation/rpc.js.map +1 -1
- package/esm/common/client/client-protocol.d.ts +6 -0
- package/esm/common/client/client-protocol.js +2 -0
- package/esm/common/client/client-protocol.js.map +1 -0
- package/esm/common/client/index.d.ts +2 -0
- package/esm/common/client/index.js +3 -0
- package/esm/common/client/index.js.map +1 -0
- package/esm/common/client/rpc-client-registry.d.ts +14 -0
- package/esm/common/client/rpc-client-registry.js +51 -0
- package/esm/common/client/rpc-client-registry.js.map +1 -0
- package/esm/common/constants.d.ts +3 -1
- package/esm/common/constants.js +3 -1
- package/esm/common/constants.js.map +1 -1
- package/esm/common/converter/converter-protocol.d.ts +6 -2
- package/esm/common/converter/converter-protocol.js +1 -0
- package/esm/common/converter/converter-protocol.js.map +1 -1
- package/esm/common/endpoint/endpoint-protocol.d.ts +3 -0
- package/esm/common/endpoint/endpoint-resolver.d.ts +2 -0
- package/esm/common/endpoint/endpoint-resolver.js +17 -3
- package/esm/common/endpoint/endpoint-resolver.js.map +1 -1
- package/esm/common/error/error.d.ts +23 -0
- package/esm/common/error/error.js +34 -2
- package/esm/common/error/error.js.map +1 -1
- package/esm/common/index.d.ts +6 -6
- package/esm/common/index.js +6 -6
- package/esm/common/index.js.map +1 -1
- package/esm/common/module.js +5 -4
- package/esm/common/module.js.map +1 -1
- package/esm/common/processor/client-config-processor.d.ts +2 -2
- package/esm/common/processor/client-config-processor.js.map +1 -1
- package/esm/common/processor/processor-protocol.d.ts +2 -2
- package/esm/common/protocol/index.d.ts +1 -0
- package/esm/common/protocol/index.js +2 -0
- package/esm/common/protocol/index.js.map +1 -0
- package/esm/common/protocol/json-rpc.d.ts +42 -0
- package/esm/common/protocol/json-rpc.js +48 -0
- package/esm/common/protocol/json-rpc.js.map +1 -0
- package/esm/common/proxy/index.d.ts +1 -4
- package/esm/common/proxy/index.js +1 -4
- package/esm/common/proxy/index.js.map +1 -1
- package/esm/common/proxy/rpc-proxy.d.ts +6 -0
- package/esm/common/proxy/rpc-proxy.js +40 -0
- package/esm/common/proxy/rpc-proxy.js.map +1 -0
- package/esm/common/transport/http-transport.d.ts +50 -0
- package/esm/common/transport/http-transport.js +98 -0
- package/esm/common/transport/http-transport.js.map +1 -0
- package/esm/common/transport/index.d.ts +4 -0
- package/esm/common/transport/index.js +5 -0
- package/esm/common/transport/index.js.map +1 -0
- package/esm/common/transport/transport-protocol.d.ts +12 -0
- package/esm/common/transport/transport-protocol.js +2 -0
- package/esm/common/transport/transport-protocol.js.map +1 -0
- package/esm/common/transport/transport-provider.d.ts +34 -0
- package/esm/common/transport/transport-provider.js +103 -0
- package/esm/common/transport/transport-provider.js.map +1 -0
- package/esm/common/transport/websocket-transport.d.ts +54 -0
- package/esm/common/transport/websocket-transport.js +144 -0
- package/esm/common/transport/websocket-transport.js.map +1 -0
- package/esm/common/utils/index.d.ts +1 -1
- package/esm/common/utils/index.js +1 -1
- package/esm/common/utils/index.js.map +1 -1
- package/esm/common/utils/rpc-method-util.d.ts +10 -0
- package/esm/common/utils/rpc-method-util.js +28 -0
- package/esm/common/utils/rpc-method-util.js.map +1 -0
- package/esm/common/utils/rpc-util.d.ts +9 -9
- package/esm/common/utils/rpc-util.js +24 -30
- package/esm/common/utils/rpc-util.js.map +1 -1
- package/esm/node/connection/connection-protocol.d.ts +26 -0
- package/esm/node/connection/connection-protocol.js +3 -0
- package/esm/node/connection/connection-protocol.js.map +1 -0
- package/esm/node/connection/index.d.ts +4 -0
- package/esm/node/connection/index.js +5 -0
- package/esm/node/connection/index.js.map +1 -0
- package/esm/node/connection/rpc-connection-manager.d.ts +10 -0
- package/esm/node/connection/rpc-connection-manager.js +35 -0
- package/esm/node/connection/rpc-connection-manager.js.map +1 -0
- package/esm/node/connection/rpc-connection.d.ts +33 -0
- package/esm/node/connection/rpc-connection.js +106 -0
- package/esm/node/connection/rpc-connection.js.map +1 -0
- package/esm/node/connection/rpc-context.d.ts +14 -0
- package/esm/node/connection/rpc-context.js +29 -0
- package/esm/node/connection/rpc-context.js.map +1 -0
- package/esm/node/index.d.ts +3 -2
- package/esm/node/index.js +3 -2
- package/esm/node/index.js.map +1 -1
- package/esm/node/server/index.d.ts +2 -0
- package/esm/node/server/index.js +3 -0
- package/esm/node/server/index.js.map +1 -0
- package/esm/node/server/rpc-handler-adapter.d.ts +15 -0
- package/esm/node/server/rpc-handler-adapter.js +74 -0
- package/esm/node/server/rpc-handler-adapter.js.map +1 -0
- package/esm/node/server/rpc-invoker.d.ts +28 -0
- package/esm/node/server/rpc-invoker.js +113 -0
- package/esm/node/server/rpc-invoker.js.map +1 -0
- package/esm/node/test/websocket-fixture-protocol.d.ts +36 -0
- package/esm/node/test/websocket-fixture-protocol.js +7 -0
- package/esm/node/test/websocket-fixture-protocol.js.map +1 -0
- package/esm/node/test/websocket-fixture.d.ts +40 -0
- package/esm/node/test/websocket-fixture.js +128 -0
- package/esm/node/test/websocket-fixture.js.map +1 -0
- package/esm/node/websocket/index.d.ts +4 -0
- package/esm/node/websocket/index.js +5 -0
- package/esm/node/websocket/index.js.map +1 -0
- package/esm/node/websocket/rpc-websocket-server.d.ts +45 -0
- package/esm/node/websocket/rpc-websocket-server.js +167 -0
- package/esm/node/websocket/rpc-websocket-server.js.map +1 -0
- package/esm/node/websocket/websocket-connection.d.ts +55 -0
- package/esm/node/websocket/websocket-connection.js +181 -0
- package/esm/node/websocket/websocket-connection.js.map +1 -0
- package/esm/node/websocket/websocket-exchange.d.ts +38 -0
- package/esm/node/websocket/websocket-exchange.js +124 -0
- package/esm/node/websocket/websocket-exchange.js.map +1 -0
- package/esm/node/websocket/websocket-frames.d.ts +31 -0
- package/esm/node/websocket/websocket-frames.js +119 -0
- package/esm/node/websocket/websocket-frames.js.map +1 -0
- package/lib/common/annotation/index.d.ts +2 -0
- package/lib/common/annotation/index.d.ts.map +1 -1
- package/lib/common/annotation/index.js +2 -0
- package/lib/common/annotation/index.js.map +1 -1
- package/lib/common/annotation/rpc-client.d.ts +8 -0
- package/lib/common/annotation/rpc-client.d.ts.map +1 -0
- package/lib/common/annotation/rpc-client.js +21 -0
- package/lib/common/annotation/rpc-client.js.map +1 -0
- package/lib/common/annotation/rpc-protocol.d.ts +8 -0
- package/lib/common/annotation/rpc-protocol.d.ts.map +1 -0
- package/lib/common/annotation/rpc-protocol.js +5 -0
- package/lib/common/annotation/rpc-protocol.js.map +1 -0
- package/lib/common/annotation/rpc.d.ts +4 -0
- package/lib/common/annotation/rpc.d.ts.map +1 -1
- package/lib/common/annotation/rpc.js +12 -16
- package/lib/common/annotation/rpc.js.map +1 -1
- package/lib/common/client/client-protocol.d.ts +7 -0
- package/lib/common/client/client-protocol.d.ts.map +1 -0
- package/lib/common/client/client-protocol.js +5 -0
- package/lib/common/client/client-protocol.js.map +1 -0
- package/lib/common/client/index.d.ts +3 -0
- package/lib/common/client/index.d.ts.map +1 -0
- package/lib/common/{handler → client}/index.js +2 -2
- package/lib/common/client/index.js.map +1 -0
- package/lib/common/client/rpc-client-registry.d.ts +15 -0
- package/lib/common/client/rpc-client-registry.d.ts.map +1 -0
- package/lib/common/client/rpc-client-registry.js +54 -0
- package/lib/common/client/rpc-client-registry.js.map +1 -0
- package/lib/common/constants.d.ts +3 -1
- package/lib/common/constants.d.ts.map +1 -1
- package/lib/common/constants.js +4 -2
- package/lib/common/constants.js.map +1 -1
- package/lib/common/converter/converter-protocol.d.ts +6 -2
- package/lib/common/converter/converter-protocol.d.ts.map +1 -1
- package/lib/common/converter/converter-protocol.js +1 -0
- package/lib/common/converter/converter-protocol.js.map +1 -1
- package/lib/common/endpoint/endpoint-protocol.d.ts +3 -0
- package/lib/common/endpoint/endpoint-protocol.d.ts.map +1 -1
- package/lib/common/endpoint/endpoint-resolver.d.ts +2 -0
- package/lib/common/endpoint/endpoint-resolver.d.ts.map +1 -1
- package/lib/common/endpoint/endpoint-resolver.js +16 -2
- package/lib/common/endpoint/endpoint-resolver.js.map +1 -1
- package/lib/common/error/error.d.ts +23 -0
- package/lib/common/error/error.d.ts.map +1 -1
- package/lib/common/error/error.js +35 -2
- package/lib/common/error/error.js.map +1 -1
- package/lib/common/index.d.ts +6 -6
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +6 -6
- package/lib/common/index.js.map +1 -1
- package/lib/common/module.d.ts.map +1 -1
- package/lib/common/module.js +4 -3
- package/lib/common/module.js.map +1 -1
- package/lib/common/processor/client-config-processor.d.ts +2 -2
- package/lib/common/processor/client-config-processor.d.ts.map +1 -1
- package/lib/common/processor/client-config-processor.js.map +1 -1
- package/lib/common/processor/processor-protocol.d.ts +2 -2
- package/lib/common/processor/processor-protocol.d.ts.map +1 -1
- package/lib/common/protocol/index.d.ts +2 -0
- package/lib/common/protocol/index.d.ts.map +1 -0
- package/lib/common/{channal → protocol}/index.js +1 -2
- package/lib/common/protocol/index.js.map +1 -0
- package/lib/common/protocol/json-rpc.d.ts +43 -0
- package/lib/common/protocol/json-rpc.d.ts.map +1 -0
- package/lib/common/protocol/json-rpc.js +51 -0
- package/lib/common/protocol/json-rpc.js.map +1 -0
- package/lib/common/proxy/index.d.ts +1 -4
- package/lib/common/proxy/index.d.ts.map +1 -1
- package/lib/common/proxy/index.js +1 -4
- package/lib/common/proxy/index.js.map +1 -1
- package/lib/common/proxy/rpc-proxy.d.ts +7 -0
- package/lib/common/proxy/rpc-proxy.d.ts.map +1 -0
- package/lib/common/proxy/rpc-proxy.js +43 -0
- package/lib/common/proxy/rpc-proxy.js.map +1 -0
- package/lib/common/transport/http-transport.d.ts +51 -0
- package/lib/common/transport/http-transport.d.ts.map +1 -0
- package/lib/common/transport/http-transport.js +102 -0
- package/lib/common/transport/http-transport.js.map +1 -0
- package/lib/common/transport/index.d.ts +5 -0
- package/lib/common/transport/index.d.ts.map +1 -0
- package/lib/common/{factory → transport}/index.js +4 -4
- package/lib/common/transport/index.js.map +1 -0
- package/lib/common/transport/transport-protocol.d.ts +13 -0
- package/lib/common/transport/transport-protocol.d.ts.map +1 -0
- package/lib/common/transport/transport-protocol.js +5 -0
- package/lib/common/transport/transport-protocol.js.map +1 -0
- package/lib/common/transport/transport-provider.d.ts +35 -0
- package/lib/common/transport/transport-provider.d.ts.map +1 -0
- package/lib/common/transport/transport-provider.js +106 -0
- package/lib/common/transport/transport-provider.js.map +1 -0
- package/lib/common/transport/websocket-transport.d.ts +55 -0
- package/lib/common/transport/websocket-transport.d.ts.map +1 -0
- package/lib/common/transport/websocket-transport.js +148 -0
- package/lib/common/transport/websocket-transport.js.map +1 -0
- package/lib/common/utils/index.d.ts +1 -1
- package/lib/common/utils/index.d.ts.map +1 -1
- package/lib/common/utils/index.js +1 -1
- package/lib/common/utils/index.js.map +1 -1
- package/lib/common/utils/rpc-method-util.d.ts +11 -0
- package/lib/common/utils/rpc-method-util.d.ts.map +1 -0
- package/lib/common/utils/rpc-method-util.js +31 -0
- package/lib/common/utils/rpc-method-util.js.map +1 -0
- package/lib/common/utils/rpc-util.d.ts +9 -9
- package/lib/common/utils/rpc-util.d.ts.map +1 -1
- package/lib/common/utils/rpc-util.js +24 -30
- package/lib/common/utils/rpc-util.js.map +1 -1
- package/lib/node/connection/connection-protocol.d.ts +27 -0
- package/lib/node/connection/connection-protocol.d.ts.map +1 -0
- package/lib/node/connection/connection-protocol.js +6 -0
- package/lib/node/connection/connection-protocol.js.map +1 -0
- package/lib/node/connection/index.d.ts +5 -0
- package/lib/node/connection/index.d.ts.map +1 -0
- package/lib/node/{channel → connection}/index.js +4 -4
- package/lib/node/connection/index.js.map +1 -0
- package/lib/node/connection/rpc-connection-manager.d.ts +11 -0
- package/lib/node/connection/rpc-connection-manager.d.ts.map +1 -0
- package/lib/node/connection/rpc-connection-manager.js +38 -0
- package/lib/node/connection/rpc-connection-manager.js.map +1 -0
- package/lib/node/connection/rpc-connection.d.ts +34 -0
- package/lib/node/connection/rpc-connection.d.ts.map +1 -0
- package/lib/node/connection/rpc-connection.js +110 -0
- package/lib/node/connection/rpc-connection.js.map +1 -0
- package/lib/node/connection/rpc-context.d.ts +15 -0
- package/lib/node/connection/rpc-context.d.ts.map +1 -0
- package/lib/node/connection/rpc-context.js +33 -0
- package/lib/node/connection/rpc-context.js.map +1 -0
- package/lib/node/index.d.ts +3 -2
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +3 -2
- package/lib/node/index.js.map +1 -1
- package/lib/node/rpc-http.spec.d.ts +2 -0
- package/lib/node/rpc-http.spec.d.ts.map +1 -0
- package/lib/node/rpc-http.spec.js +121 -0
- package/lib/node/rpc-http.spec.js.map +1 -0
- package/lib/node/rpc-websocket.spec.d.ts +6 -0
- package/lib/node/rpc-websocket.spec.d.ts.map +1 -0
- package/lib/node/rpc-websocket.spec.js +196 -0
- package/lib/node/rpc-websocket.spec.js.map +1 -0
- package/lib/node/server/index.d.ts +3 -0
- package/lib/node/server/index.d.ts.map +1 -0
- package/lib/node/{handler → server}/index.js +2 -2
- package/lib/node/server/index.js.map +1 -0
- package/lib/node/server/rpc-handler-adapter.d.ts +16 -0
- package/lib/node/server/rpc-handler-adapter.d.ts.map +1 -0
- package/lib/node/{handler/handler-adapter.js → server/rpc-handler-adapter.js} +40 -18
- package/lib/node/server/rpc-handler-adapter.js.map +1 -0
- package/lib/node/server/rpc-invoker.d.ts +29 -0
- package/lib/node/server/rpc-invoker.d.ts.map +1 -0
- package/lib/node/server/rpc-invoker.js +116 -0
- package/lib/node/server/rpc-invoker.js.map +1 -0
- package/lib/node/test/websocket-fixture-protocol.d.ts +37 -0
- package/lib/node/test/websocket-fixture-protocol.d.ts.map +1 -0
- package/lib/node/test/websocket-fixture-protocol.js +10 -0
- package/lib/node/test/websocket-fixture-protocol.js.map +1 -0
- package/lib/node/test/websocket-fixture.d.ts +41 -0
- package/lib/node/test/websocket-fixture.d.ts.map +1 -0
- package/lib/node/test/websocket-fixture.js +135 -0
- package/lib/node/test/websocket-fixture.js.map +1 -0
- package/lib/node/websocket/index.d.ts +5 -0
- package/lib/node/websocket/index.d.ts.map +1 -0
- package/lib/node/websocket/index.js +21 -0
- package/lib/node/websocket/index.js.map +1 -0
- package/lib/node/websocket/rpc-websocket-server.d.ts +46 -0
- package/lib/node/websocket/rpc-websocket-server.d.ts.map +1 -0
- package/lib/node/websocket/rpc-websocket-server.js +170 -0
- package/lib/node/websocket/rpc-websocket-server.js.map +1 -0
- package/lib/node/websocket/websocket-connection.d.ts +56 -0
- package/lib/node/websocket/websocket-connection.d.ts.map +1 -0
- package/lib/node/websocket/websocket-connection.js +185 -0
- package/lib/node/websocket/websocket-connection.js.map +1 -0
- package/lib/node/websocket/websocket-exchange.d.ts +39 -0
- package/lib/node/websocket/websocket-exchange.d.ts.map +1 -0
- package/lib/node/websocket/websocket-exchange.js +128 -0
- package/lib/node/websocket/websocket-exchange.js.map +1 -0
- package/lib/node/websocket/websocket-frames.d.ts +32 -0
- package/lib/node/websocket/websocket-frames.d.ts.map +1 -0
- package/lib/node/websocket/websocket-frames.js +124 -0
- package/lib/node/websocket/websocket-frames.js.map +1 -0
- package/lib/node/websocket/websocket-frames.spec.d.ts +2 -0
- package/lib/node/websocket/websocket-frames.spec.d.ts.map +1 -0
- package/lib/node/websocket/websocket-frames.spec.js +59 -0
- package/lib/node/websocket/websocket-frames.spec.js.map +1 -0
- package/package.json +28 -25
- package/src/common/annotation/index.ts +2 -0
- package/src/common/annotation/rpc-client.ts +17 -0
- package/src/common/annotation/rpc-protocol.ts +8 -0
- package/src/common/annotation/rpc.ts +13 -21
- package/src/common/client/client-protocol.ts +7 -0
- package/src/common/client/index.ts +2 -0
- package/src/common/client/rpc-client-registry.ts +42 -0
- package/src/common/constants.ts +4 -1
- package/src/common/converter/converter-protocol.ts +7 -2
- package/src/common/endpoint/endpoint-protocol.ts +3 -0
- package/src/common/endpoint/endpoint-resolver.ts +18 -4
- package/src/common/error/error.ts +41 -2
- package/src/common/index.ts +6 -6
- package/src/common/module.ts +7 -8
- package/src/common/processor/client-config-processor.ts +2 -2
- package/src/common/processor/processor-protocol.ts +2 -2
- package/src/common/protocol/index.ts +1 -0
- package/src/common/protocol/json-rpc.ts +74 -0
- package/src/common/proxy/index.ts +1 -5
- package/src/common/proxy/rpc-proxy.ts +42 -0
- package/src/common/transport/http-transport.ts +134 -0
- package/src/common/transport/index.ts +4 -0
- package/src/common/transport/transport-protocol.ts +16 -0
- package/src/common/transport/transport-provider.ts +86 -0
- package/src/common/transport/websocket-transport.ts +171 -0
- package/src/common/utils/index.ts +1 -1
- package/src/common/utils/rpc-method-util.ts +26 -0
- package/src/common/utils/rpc-util.ts +24 -35
- package/src/node/connection/connection-protocol.ts +30 -0
- package/src/node/connection/index.ts +3 -0
- package/src/node/connection/rpc-connection-manager.ts +29 -0
- package/src/node/connection/rpc-connection.ts +122 -0
- package/src/node/connection/rpc-context.ts +29 -0
- package/src/node/index.ts +3 -2
- package/src/node/rpc-http.spec.ts +126 -0
- package/src/node/rpc-websocket.spec.ts +196 -0
- package/src/node/server/index.ts +2 -0
- package/src/node/server/rpc-handler-adapter.ts +60 -0
- package/src/node/server/rpc-invoker.ts +104 -0
- package/src/node/test/websocket-fixture-protocol.ts +32 -0
- package/src/node/test/websocket-fixture.ts +122 -0
- package/src/node/websocket/index.ts +4 -0
- package/src/node/websocket/rpc-websocket-server.ts +163 -0
- package/src/node/websocket/websocket-connection.ts +198 -0
- package/src/node/websocket/websocket-exchange.ts +138 -0
- package/src/node/websocket/websocket-frames.spec.ts +62 -0
- package/src/node/websocket/websocket-frames.ts +122 -0
- package/esm/common/channal/channel-protocol.d.ts +0 -51
- package/esm/common/channal/channel-protocol.js +0 -34
- package/esm/common/channal/channel-protocol.js.map +0 -1
- package/esm/common/channal/http-channel.d.ts +0 -8
- package/esm/common/channal/http-channel.js +0 -22
- package/esm/common/channal/http-channel.js.map +0 -1
- package/esm/common/channal/index.d.ts +0 -2
- package/esm/common/channal/index.js +0 -3
- package/esm/common/channal/index.js.map +0 -1
- package/esm/common/factory/connection-factory.d.ts +0 -9
- package/esm/common/factory/connection-factory.js +0 -25
- package/esm/common/factory/connection-factory.js.map +0 -1
- package/esm/common/factory/index.d.ts +0 -4
- package/esm/common/factory/index.js +0 -5
- package/esm/common/factory/index.js.map +0 -1
- package/esm/common/factory/proxy-factory.d.ts +0 -56
- package/esm/common/factory/proxy-factory.js +0 -177
- package/esm/common/factory/proxy-factory.js.map +0 -1
- package/esm/common/factory/reader.d.ts +0 -15
- package/esm/common/factory/reader.js +0 -44
- package/esm/common/factory/reader.js.map +0 -1
- package/esm/common/factory/writer.d.ts +0 -9
- package/esm/common/factory/writer.js +0 -21
- package/esm/common/factory/writer.js.map +0 -1
- package/esm/common/handler/connection-handler.d.ts +0 -6
- package/esm/common/handler/connection-handler.js +0 -4
- package/esm/common/handler/connection-handler.js.map +0 -1
- package/esm/common/handler/handler-protocol.d.ts +0 -6
- package/esm/common/handler/handler-protocol.js +0 -2
- package/esm/common/handler/handler-protocol.js.map +0 -1
- package/esm/common/handler/index.d.ts +0 -2
- package/esm/common/handler/index.js +0 -3
- package/esm/common/handler/index.js.map +0 -1
- package/esm/common/proxy/delegating-http-proxy-creator.d.ts +0 -23
- package/esm/common/proxy/delegating-http-proxy-creator.js +0 -86
- package/esm/common/proxy/delegating-http-proxy-creator.js.map +0 -1
- package/esm/common/proxy/http-proxy-creator.d.ts +0 -42
- package/esm/common/proxy/http-proxy-creator.js +0 -139
- package/esm/common/proxy/http-proxy-creator.js.map +0 -1
- package/esm/common/proxy/proxy-protocol.d.ts +0 -20
- package/esm/common/proxy/proxy-protocol.js +0 -3
- package/esm/common/proxy/proxy-protocol.js.map +0 -1
- package/esm/common/proxy/proxy-provider.d.ts +0 -9
- package/esm/common/proxy/proxy-provider.js +0 -40
- package/esm/common/proxy/proxy-provider.js.map +0 -1
- package/esm/common/utils/logger.d.ts +0 -8
- package/esm/common/utils/logger.js +0 -18
- package/esm/common/utils/logger.js.map +0 -1
- package/esm/node/channel/channel-manager.d.ts +0 -9
- package/esm/node/channel/channel-manager.js +0 -56
- package/esm/node/channel/channel-manager.js.map +0 -1
- package/esm/node/channel/channel-middleware.d.ts +0 -7
- package/esm/node/channel/channel-middleware.js +0 -37
- package/esm/node/channel/channel-middleware.js.map +0 -1
- package/esm/node/channel/channel-protocol.d.ts +0 -12
- package/esm/node/channel/channel-protocol.js +0 -6
- package/esm/node/channel/channel-protocol.js.map +0 -1
- package/esm/node/channel/channel-strategy.d.ts +0 -9
- package/esm/node/channel/channel-strategy.js +0 -61
- package/esm/node/channel/channel-strategy.js.map +0 -1
- package/esm/node/channel/index.d.ts +0 -4
- package/esm/node/channel/index.js +0 -5
- package/esm/node/channel/index.js.map +0 -1
- package/esm/node/handler/handler-adapter.d.ts +0 -13
- package/esm/node/handler/handler-adapter.js +0 -52
- package/esm/node/handler/handler-adapter.js.map +0 -1
- package/esm/node/handler/handler-protocol.d.ts +0 -1
- package/esm/node/handler/handler-protocol.js +0 -2
- package/esm/node/handler/handler-protocol.js.map +0 -1
- package/esm/node/handler/index.d.ts +0 -2
- package/esm/node/handler/index.js +0 -3
- package/esm/node/handler/index.js.map +0 -1
- package/lib/common/channal/channel-protocol.d.ts +0 -52
- package/lib/common/channal/channel-protocol.d.ts.map +0 -1
- package/lib/common/channal/channel-protocol.js +0 -38
- package/lib/common/channal/channel-protocol.js.map +0 -1
- package/lib/common/channal/http-channel.d.ts +0 -9
- package/lib/common/channal/http-channel.d.ts.map +0 -1
- package/lib/common/channal/http-channel.js +0 -26
- package/lib/common/channal/http-channel.js.map +0 -1
- package/lib/common/channal/index.d.ts +0 -3
- package/lib/common/channal/index.d.ts.map +0 -1
- package/lib/common/channal/index.js.map +0 -1
- package/lib/common/factory/connection-factory.d.ts +0 -10
- package/lib/common/factory/connection-factory.d.ts.map +0 -1
- package/lib/common/factory/connection-factory.js +0 -28
- package/lib/common/factory/connection-factory.js.map +0 -1
- package/lib/common/factory/index.d.ts +0 -5
- package/lib/common/factory/index.d.ts.map +0 -1
- package/lib/common/factory/index.js.map +0 -1
- package/lib/common/factory/proxy-factory.d.ts +0 -57
- package/lib/common/factory/proxy-factory.d.ts.map +0 -1
- package/lib/common/factory/proxy-factory.js +0 -182
- package/lib/common/factory/proxy-factory.js.map +0 -1
- package/lib/common/factory/reader.d.ts +0 -16
- package/lib/common/factory/reader.d.ts.map +0 -1
- package/lib/common/factory/reader.js +0 -48
- package/lib/common/factory/reader.js.map +0 -1
- package/lib/common/factory/writer.d.ts +0 -10
- package/lib/common/factory/writer.d.ts.map +0 -1
- package/lib/common/factory/writer.js +0 -25
- package/lib/common/factory/writer.js.map +0 -1
- package/lib/common/handler/connection-handler.d.ts +0 -7
- package/lib/common/handler/connection-handler.d.ts.map +0 -1
- package/lib/common/handler/connection-handler.js +0 -8
- package/lib/common/handler/connection-handler.js.map +0 -1
- package/lib/common/handler/handler-protocol.d.ts +0 -7
- package/lib/common/handler/handler-protocol.d.ts.map +0 -1
- package/lib/common/handler/handler-protocol.js +0 -5
- package/lib/common/handler/handler-protocol.js.map +0 -1
- package/lib/common/handler/index.d.ts +0 -3
- package/lib/common/handler/index.d.ts.map +0 -1
- package/lib/common/handler/index.js.map +0 -1
- package/lib/common/proxy/delegating-http-proxy-creator.d.ts +0 -24
- package/lib/common/proxy/delegating-http-proxy-creator.d.ts.map +0 -1
- package/lib/common/proxy/delegating-http-proxy-creator.js +0 -89
- package/lib/common/proxy/delegating-http-proxy-creator.js.map +0 -1
- package/lib/common/proxy/http-proxy-creator.d.ts +0 -43
- package/lib/common/proxy/http-proxy-creator.d.ts.map +0 -1
- package/lib/common/proxy/http-proxy-creator.js +0 -143
- package/lib/common/proxy/http-proxy-creator.js.map +0 -1
- package/lib/common/proxy/proxy-protocol.d.ts +0 -21
- package/lib/common/proxy/proxy-protocol.d.ts.map +0 -1
- package/lib/common/proxy/proxy-protocol.js +0 -6
- package/lib/common/proxy/proxy-protocol.js.map +0 -1
- package/lib/common/proxy/proxy-provider.d.ts +0 -10
- package/lib/common/proxy/proxy-provider.d.ts.map +0 -1
- package/lib/common/proxy/proxy-provider.js +0 -43
- package/lib/common/proxy/proxy-provider.js.map +0 -1
- package/lib/common/utils/logger.d.ts +0 -9
- package/lib/common/utils/logger.d.ts.map +0 -1
- package/lib/common/utils/logger.js +0 -22
- package/lib/common/utils/logger.js.map +0 -1
- package/lib/node/channel/channel-manager.d.ts +0 -10
- package/lib/node/channel/channel-manager.d.ts.map +0 -1
- package/lib/node/channel/channel-manager.js +0 -59
- package/lib/node/channel/channel-manager.js.map +0 -1
- package/lib/node/channel/channel-middleware.d.ts +0 -8
- package/lib/node/channel/channel-middleware.d.ts.map +0 -1
- package/lib/node/channel/channel-middleware.js +0 -40
- package/lib/node/channel/channel-middleware.js.map +0 -1
- package/lib/node/channel/channel-protocol.d.ts +0 -13
- package/lib/node/channel/channel-protocol.d.ts.map +0 -1
- package/lib/node/channel/channel-protocol.js +0 -9
- package/lib/node/channel/channel-protocol.js.map +0 -1
- package/lib/node/channel/channel-strategy.d.ts +0 -10
- package/lib/node/channel/channel-strategy.d.ts.map +0 -1
- package/lib/node/channel/channel-strategy.js +0 -64
- package/lib/node/channel/channel-strategy.js.map +0 -1
- package/lib/node/channel/index.d.ts +0 -5
- package/lib/node/channel/index.d.ts.map +0 -1
- package/lib/node/channel/index.js.map +0 -1
- package/lib/node/handler/handler-adapter.d.ts +0 -14
- package/lib/node/handler/handler-adapter.d.ts.map +0 -1
- package/lib/node/handler/handler-adapter.js.map +0 -1
- package/lib/node/handler/handler-protocol.d.ts +0 -2
- package/lib/node/handler/handler-protocol.d.ts.map +0 -1
- package/lib/node/handler/handler-protocol.js +0 -5
- package/lib/node/handler/handler-protocol.js.map +0 -1
- package/lib/node/handler/index.d.ts +0 -3
- package/lib/node/handler/index.d.ts.map +0 -1
- package/lib/node/handler/index.js.map +0 -1
- package/src/common/channal/channel-protocol.ts +0 -82
- package/src/common/channal/http-channel.ts +0 -30
- package/src/common/channal/index.ts +0 -2
- package/src/common/factory/connection-factory.ts +0 -21
- package/src/common/factory/index.ts +0 -4
- package/src/common/factory/proxy-factory.ts +0 -219
- package/src/common/factory/reader.ts +0 -50
- package/src/common/factory/writer.ts +0 -26
- package/src/common/handler/connection-handler.ts +0 -7
- package/src/common/handler/handler-protocol.ts +0 -8
- package/src/common/handler/index.ts +0 -2
- package/src/common/proxy/delegating-http-proxy-creator.ts +0 -68
- package/src/common/proxy/http-proxy-creator.ts +0 -179
- package/src/common/proxy/proxy-protocol.ts +0 -26
- package/src/common/proxy/proxy-provider.ts +0 -29
- package/src/common/utils/logger.ts +0 -23
- package/src/node/channel/channel-manager.ts +0 -44
- package/src/node/channel/channel-middleware.ts +0 -27
- package/src/node/channel/channel-protocol.ts +0 -21
- package/src/node/channel/channel-strategy.ts +0 -56
- package/src/node/channel/index.ts +0 -4
- package/src/node/handler/handler-adapter.ts +0 -38
- package/src/node/handler/handler-protocol.ts +0 -1
- package/src/node/handler/index.ts +0 -2
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { HttpHeaders, HttpMethod, MediaType, RequestConfig, RestOperations, DefaultRestOperations, XML_HTTP_REQUEST } from '@celljs/http';
|
|
2
|
+
import { JsonRpc } from '../protocol';
|
|
3
|
+
import { EndpointResolver } from '../endpoint';
|
|
4
|
+
import { ClientConfigProcessor } from '../processor';
|
|
5
|
+
import { RpcTransport } from './transport-protocol';
|
|
6
|
+
|
|
7
|
+
export interface MergeOptions {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
/** Milliseconds to wait for more calls. */
|
|
10
|
+
timerDelay: number;
|
|
11
|
+
maxCount: number;
|
|
12
|
+
/** Bytes. */
|
|
13
|
+
maxLength: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface HttpTransportOptions {
|
|
17
|
+
endpointResolver: EndpointResolver;
|
|
18
|
+
restOperations?: RestOperations;
|
|
19
|
+
clientConfig?: RequestConfig;
|
|
20
|
+
clientConfigProcessor?: ClientConfigProcessor;
|
|
21
|
+
merge?: Partial<MergeOptions>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Pending {
|
|
25
|
+
request: JsonRpc.Request;
|
|
26
|
+
body: string;
|
|
27
|
+
resolve(response: JsonRpc.Response): void;
|
|
28
|
+
reject(error: unknown): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Batch {
|
|
32
|
+
pending: Pending[];
|
|
33
|
+
length: number;
|
|
34
|
+
timer: ReturnType<typeof setTimeout>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* JSON-RPC over HTTP: `POST <endpoint of the service>` with one request, or with the requests made
|
|
39
|
+
* within `merge.timerDelay` as a batch (an array) when `merge.enabled`.
|
|
40
|
+
*/
|
|
41
|
+
export class HttpTransport implements RpcTransport {
|
|
42
|
+
|
|
43
|
+
static readonly DEFAULT_MERGE: MergeOptions = { enabled: false, timerDelay: 35, maxCount: 100, maxLength: 5242880 };
|
|
44
|
+
|
|
45
|
+
protected seq = 0;
|
|
46
|
+
protected readonly batches = new Map<string, Batch>();
|
|
47
|
+
protected readonly merge: MergeOptions;
|
|
48
|
+
protected readonly restOperations: RestOperations;
|
|
49
|
+
|
|
50
|
+
constructor(protected readonly options: HttpTransportOptions) {
|
|
51
|
+
this.merge = { ...HttpTransport.DEFAULT_MERGE, ...options.merge };
|
|
52
|
+
this.restOperations = options.restOperations ?? new DefaultRestOperations();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async call(service: string, method: string, params: unknown[]): Promise<JsonRpc.Response> {
|
|
56
|
+
const url = await this.options.endpointResolver.resolve(service);
|
|
57
|
+
const request = JsonRpc.request(++this.seq, method, params);
|
|
58
|
+
return new Promise<JsonRpc.Response>((resolve, reject) => {
|
|
59
|
+
const pending: Pending = { request, body: JSON.stringify(request), resolve, reject };
|
|
60
|
+
if (this.merge.enabled) {
|
|
61
|
+
this.enqueue(url, pending);
|
|
62
|
+
} else {
|
|
63
|
+
void this.send(url, [pending]);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected enqueue(url: string, pending: Pending): void {
|
|
69
|
+
let batch = this.batches.get(url);
|
|
70
|
+
if (batch && (batch.pending.length + 1 > this.merge.maxCount || batch.length + pending.body.length > this.merge.maxLength)) {
|
|
71
|
+
this.flush(url);
|
|
72
|
+
batch = undefined;
|
|
73
|
+
}
|
|
74
|
+
if (!batch) {
|
|
75
|
+
batch = { pending: [], length: 0, timer: setTimeout(() => this.flush(url), this.merge.timerDelay) };
|
|
76
|
+
this.batches.set(url, batch);
|
|
77
|
+
}
|
|
78
|
+
batch.pending.push(pending);
|
|
79
|
+
batch.length += pending.body.length;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected flush(url: string): void {
|
|
83
|
+
const batch = this.batches.get(url);
|
|
84
|
+
if (batch) {
|
|
85
|
+
this.batches.delete(url);
|
|
86
|
+
clearTimeout(batch.timer);
|
|
87
|
+
void this.send(url, batch.pending);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static parse(text: string): unknown {
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(text);
|
|
94
|
+
} catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected async send(url: string, pending: Pending[]): Promise<void> {
|
|
100
|
+
try {
|
|
101
|
+
const config: RequestConfig = {
|
|
102
|
+
...this.options.clientConfig,
|
|
103
|
+
url,
|
|
104
|
+
method: HttpMethod.POST,
|
|
105
|
+
data: pending.length === 1 ? pending[0].body : `[${pending.map(p => p.body).join(',')}]`,
|
|
106
|
+
headers: {
|
|
107
|
+
...this.options.clientConfig?.headers,
|
|
108
|
+
[HttpHeaders.CONTENT_TYPE]: MediaType.APPLICATION_JSON_UTF8,
|
|
109
|
+
[HttpHeaders.X_REQUESTED_WITH]: XML_HTTP_REQUEST,
|
|
110
|
+
},
|
|
111
|
+
// A JSON-RPC answer comes with any status; others (a 401 of a middleware) become errors of the calls.
|
|
112
|
+
validateStatus: () => true,
|
|
113
|
+
};
|
|
114
|
+
await this.options.clientConfigProcessor?.process(config);
|
|
115
|
+
const { status, statusText, data } = await this.restOperations.request(config);
|
|
116
|
+
const body = typeof data === 'string' ? HttpTransport.parse(data) : data;
|
|
117
|
+
const responses = (Array.isArray(body) ? body : [body]).filter(JsonRpc.isResponse);
|
|
118
|
+
const byId = new Map(responses.map(r => [r.id, r]));
|
|
119
|
+
for (const p of pending) {
|
|
120
|
+
const response = byId.get(p.request.id!);
|
|
121
|
+
if (response) {
|
|
122
|
+
p.resolve(response);
|
|
123
|
+
} else {
|
|
124
|
+
const message = typeof data === 'string' && data && !data.startsWith('<') ? data : `${status} ${statusText ?? ''}`.trim();
|
|
125
|
+
p.resolve(JsonRpc.error(p.request.id!, JsonRpc.SERVER_ERROR, message, { status }));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
for (const p of pending) {
|
|
130
|
+
p.reject(error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JsonRpc } from '../protocol';
|
|
2
|
+
|
|
3
|
+
/** How a proxy reaches its service: one JSON-RPC request, its response. */
|
|
4
|
+
export interface RpcTransport {
|
|
5
|
+
/** The response to `method` of `service` (its path, e.g. `GreetingServer`); rejects only when no response can come. */
|
|
6
|
+
call(service: string, method: string, params: unknown[]): Promise<JsonRpc.Response>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type RpcTransportKind = 'http' | 'websocket';
|
|
10
|
+
|
|
11
|
+
export const RpcTransportProvider = Symbol('RpcTransportProvider');
|
|
12
|
+
|
|
13
|
+
/** The transport of a service: `rpc.transport`, HTTP for services with their own `rpc.endpoint`. */
|
|
14
|
+
export interface RpcTransportProvider {
|
|
15
|
+
provide(service: string): RpcTransport;
|
|
16
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Application, ApplicationLifecycle, Autowired, Component, Value } from '@celljs/core';
|
|
2
|
+
import { RequestConfig, RestOperations } from '@celljs/http';
|
|
3
|
+
import { RpcClientRegistry } from '../client/rpc-client-registry';
|
|
4
|
+
import { EndpointResolver } from '../endpoint';
|
|
5
|
+
import { ClientConfigProcessor } from '../processor';
|
|
6
|
+
import { HttpTransport, MergeOptions } from './http-transport';
|
|
7
|
+
import { RpcTransport, RpcTransportKind, RpcTransportProvider } from './transport-protocol';
|
|
8
|
+
import { WebSocketTransport } from './websocket-transport';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* One HTTP transport, and with `rpc.transport: websocket` one WebSocket connection for the services
|
|
12
|
+
* without an endpoint of their own. When there are `@RpcClient` components, the connection opens
|
|
13
|
+
* as the application starts and reopens when it drops, so the server can call them.
|
|
14
|
+
*/
|
|
15
|
+
@Component([RpcTransportProvider, ApplicationLifecycle])
|
|
16
|
+
export class RpcTransportProviderImpl implements RpcTransportProvider, ApplicationLifecycle<Application> {
|
|
17
|
+
|
|
18
|
+
@Value('rpc.transport')
|
|
19
|
+
protected readonly kind?: RpcTransportKind;
|
|
20
|
+
|
|
21
|
+
@Value('rpc.endpoint')
|
|
22
|
+
protected readonly endpoints?: Record<string, string>;
|
|
23
|
+
|
|
24
|
+
@Value('rpc.client.config')
|
|
25
|
+
protected readonly clientConfig?: RequestConfig;
|
|
26
|
+
|
|
27
|
+
@Value('rpc.merge')
|
|
28
|
+
protected readonly merge?: Partial<MergeOptions>;
|
|
29
|
+
|
|
30
|
+
@Value('rpc.websocket')
|
|
31
|
+
protected readonly websocketOptions?: { callTimeout?: number; reconnectDelay?: number };
|
|
32
|
+
|
|
33
|
+
@Autowired(EndpointResolver)
|
|
34
|
+
protected readonly endpointResolver: EndpointResolver;
|
|
35
|
+
|
|
36
|
+
@Autowired(RestOperations)
|
|
37
|
+
protected readonly restOperations: RestOperations;
|
|
38
|
+
|
|
39
|
+
@Autowired(ClientConfigProcessor)
|
|
40
|
+
protected readonly clientConfigProcessor: ClientConfigProcessor;
|
|
41
|
+
|
|
42
|
+
@Autowired(RpcClientRegistry)
|
|
43
|
+
protected readonly clients: RpcClientRegistry;
|
|
44
|
+
|
|
45
|
+
protected http?: HttpTransport;
|
|
46
|
+
protected websocket?: WebSocketTransport;
|
|
47
|
+
|
|
48
|
+
provide(service: string): RpcTransport {
|
|
49
|
+
if (this.kind === 'websocket' && !this.endpoints?.[service]) {
|
|
50
|
+
return this.websocketTransport();
|
|
51
|
+
}
|
|
52
|
+
return this.httpTransport();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
onStart(): void {
|
|
56
|
+
if (this.kind === 'websocket' && !this.clients.empty) {
|
|
57
|
+
void this.websocketTransport().connect();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
onStop(): void {
|
|
62
|
+
this.websocket?.close();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
protected httpTransport(): HttpTransport {
|
|
66
|
+
this.http ??= new HttpTransport({
|
|
67
|
+
endpointResolver: this.endpointResolver,
|
|
68
|
+
restOperations: this.restOperations,
|
|
69
|
+
clientConfig: this.clientConfig,
|
|
70
|
+
clientConfigProcessor: this.clientConfigProcessor,
|
|
71
|
+
merge: this.merge,
|
|
72
|
+
});
|
|
73
|
+
return this.http;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected websocketTransport(): WebSocketTransport {
|
|
77
|
+
this.websocket ??= new WebSocketTransport({
|
|
78
|
+
url: () => this.endpointResolver.resolveWebSocket!(),
|
|
79
|
+
fallback: this.httpTransport(),
|
|
80
|
+
handle: request => this.clients.handle(request),
|
|
81
|
+
keepAlive: !this.clients.empty,
|
|
82
|
+
...this.websocketOptions,
|
|
83
|
+
});
|
|
84
|
+
return this.websocket;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { JsonRpc } from '../protocol';
|
|
2
|
+
import { RpcTransport } from './transport-protocol';
|
|
3
|
+
|
|
4
|
+
export interface WebSocketTransportOptions {
|
|
5
|
+
/** `ws://` or `wss://` URL of the endpoint (`/<rpc.path>/ws` of the server). */
|
|
6
|
+
url(): Promise<string>;
|
|
7
|
+
/** Used while no connection can be made: HTTP. */
|
|
8
|
+
fallback: RpcTransport;
|
|
9
|
+
/** Answers the requests of the server (`@RpcClient` components). */
|
|
10
|
+
handle?(request: JsonRpc.Request): Promise<JsonRpc.Response>;
|
|
11
|
+
/** Keep a connection open (and reconnect) even without calls: there are clients the server pushes to. */
|
|
12
|
+
keepAlive?: boolean;
|
|
13
|
+
/** Milliseconds before the first reconnection; doubles up to 30 s. Default 1000. */
|
|
14
|
+
reconnectDelay?: number;
|
|
15
|
+
/** Milliseconds a call waits for its response. Default 60000. */
|
|
16
|
+
callTimeout?: number;
|
|
17
|
+
/** Milliseconds to wait for a connection to open before using the fallback. Default 5000. */
|
|
18
|
+
connectTimeout?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Pending {
|
|
22
|
+
resolve(response: JsonRpc.Response): void;
|
|
23
|
+
timer: ReturnType<typeof setTimeout>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* JSON-RPC over one WebSocket connection for all services (methods are `<service>/<method>`), which
|
|
28
|
+
* the server can call back over (`@RpcClient`). While no connection can be opened (no `WebSocket` in
|
|
29
|
+
* this runtime, a server or platform without WebSocket support) calls go to the fallback transport.
|
|
30
|
+
* A connection that closes answers its pending calls with {@link JsonRpc.CONNECTION_CLOSED}: they are
|
|
31
|
+
* not sent again, since they may have run.
|
|
32
|
+
*/
|
|
33
|
+
export class WebSocketTransport implements RpcTransport {
|
|
34
|
+
|
|
35
|
+
static readonly MAX_RECONNECT_DELAY = 30000;
|
|
36
|
+
|
|
37
|
+
protected socket?: WebSocket;
|
|
38
|
+
protected opening?: Promise<WebSocket | undefined>;
|
|
39
|
+
protected readonly pending = new Map<JsonRpc.Id, Pending>();
|
|
40
|
+
protected seq = 0;
|
|
41
|
+
protected retryAt = 0;
|
|
42
|
+
protected delay: number;
|
|
43
|
+
protected reconnectTimer?: ReturnType<typeof setTimeout>;
|
|
44
|
+
protected closed = false;
|
|
45
|
+
|
|
46
|
+
constructor(protected readonly options: WebSocketTransportOptions) {
|
|
47
|
+
this.delay = options.reconnectDelay ?? 1000;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Whether calls go over a WebSocket connection now. */
|
|
51
|
+
get connected(): boolean {
|
|
52
|
+
return this.socket?.readyState === 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async call(service: string, method: string, params: unknown[]): Promise<JsonRpc.Response> {
|
|
56
|
+
const socket = await this.connect();
|
|
57
|
+
if (!socket) {
|
|
58
|
+
return this.options.fallback.call(service, method, params);
|
|
59
|
+
}
|
|
60
|
+
const id = ++this.seq;
|
|
61
|
+
return new Promise<JsonRpc.Response>(resolve => {
|
|
62
|
+
const timeout = this.options.callTimeout ?? 60000;
|
|
63
|
+
const timer = setTimeout(() => {
|
|
64
|
+
this.pending.delete(id);
|
|
65
|
+
resolve(JsonRpc.error(id, JsonRpc.TIMEOUT, `No response to ${service}.${method} within ${timeout} ms.`));
|
|
66
|
+
}, timeout);
|
|
67
|
+
this.pending.set(id, { resolve, timer });
|
|
68
|
+
socket.send(JSON.stringify(JsonRpc.request(id, `${service}/${method}`, params)));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Opens the connection (calls open it when needed); undefined while none can be made. */
|
|
73
|
+
connect(): Promise<WebSocket | undefined> {
|
|
74
|
+
if (this.closed || typeof WebSocket === 'undefined') {
|
|
75
|
+
return Promise.resolve(undefined);
|
|
76
|
+
}
|
|
77
|
+
if (this.socket && this.socket.readyState === 1) {
|
|
78
|
+
return Promise.resolve(this.socket);
|
|
79
|
+
}
|
|
80
|
+
if (this.opening) {
|
|
81
|
+
return this.opening;
|
|
82
|
+
}
|
|
83
|
+
if (Date.now() < this.retryAt) {
|
|
84
|
+
return Promise.resolve(undefined);
|
|
85
|
+
}
|
|
86
|
+
this.opening = this.open().finally(() => {
|
|
87
|
+
this.opening = undefined;
|
|
88
|
+
});
|
|
89
|
+
return this.opening;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Closes the connection for good: later calls use the fallback. */
|
|
93
|
+
close(): void {
|
|
94
|
+
this.closed = true;
|
|
95
|
+
clearTimeout(this.reconnectTimer);
|
|
96
|
+
this.socket?.close(1000);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
protected async open(): Promise<WebSocket | undefined> {
|
|
100
|
+
const url = await this.options.url();
|
|
101
|
+
return new Promise<WebSocket | undefined>(resolve => {
|
|
102
|
+
let opened = false;
|
|
103
|
+
const socket = new WebSocket(url);
|
|
104
|
+
// A server that never answers the upgrade (Bun < 1.4 behind node:http) must not hold the calls.
|
|
105
|
+
const timer = setTimeout(() => socket.close(), this.options.connectTimeout ?? 5000);
|
|
106
|
+
socket.onopen = () => {
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
opened = true;
|
|
109
|
+
this.socket = socket;
|
|
110
|
+
this.delay = this.options.reconnectDelay ?? 1000;
|
|
111
|
+
resolve(socket);
|
|
112
|
+
};
|
|
113
|
+
socket.onmessage = event => this.receive(socket, event.data);
|
|
114
|
+
socket.onerror = () => undefined;
|
|
115
|
+
socket.onclose = () => {
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
if (!opened) {
|
|
118
|
+
// No WebSocket endpoint (yet): HTTP for a while, then try again.
|
|
119
|
+
this.retryAt = Date.now() + this.delay;
|
|
120
|
+
this.delay = Math.min(this.delay * 2, WebSocketTransport.MAX_RECONNECT_DELAY);
|
|
121
|
+
resolve(undefined);
|
|
122
|
+
} else {
|
|
123
|
+
this.socket = undefined;
|
|
124
|
+
this.failPending();
|
|
125
|
+
}
|
|
126
|
+
this.scheduleReconnect();
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected scheduleReconnect(): void {
|
|
132
|
+
if (!this.options.keepAlive || this.closed) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
clearTimeout(this.reconnectTimer);
|
|
136
|
+
this.reconnectTimer = setTimeout(() => void this.connect(), Math.max(this.retryAt - Date.now(), this.delay));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
protected failPending(): void {
|
|
140
|
+
for (const [id, pending] of this.pending) {
|
|
141
|
+
clearTimeout(pending.timer);
|
|
142
|
+
pending.resolve(JsonRpc.error(id, JsonRpc.CONNECTION_CLOSED, 'The WebSocket connection closed before the response arrived; the call may or may not have run.'));
|
|
143
|
+
}
|
|
144
|
+
this.pending.clear();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
protected receive(socket: WebSocket, data: unknown): void {
|
|
148
|
+
let message: unknown;
|
|
149
|
+
try {
|
|
150
|
+
message = JSON.parse(String(data));
|
|
151
|
+
} catch {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (JsonRpc.isResponse(message)) {
|
|
155
|
+
const pending = message.id === null ? undefined : this.pending.get(message.id);
|
|
156
|
+
if (pending) {
|
|
157
|
+
clearTimeout(pending.timer);
|
|
158
|
+
this.pending.delete(message.id!);
|
|
159
|
+
pending.resolve(message);
|
|
160
|
+
}
|
|
161
|
+
} else if (JsonRpc.isRequest(message)) {
|
|
162
|
+
const request = message;
|
|
163
|
+
const handle = this.options.handle ?? (async (r: JsonRpc.Request) => JsonRpc.error(r.id ?? null, JsonRpc.METHOD_NOT_FOUND, `No @RpcClient for ${r.method}.`));
|
|
164
|
+
void handle(request).then(response => {
|
|
165
|
+
if (request.id !== undefined && socket.readyState === 1) {
|
|
166
|
+
socket.send(JSON.stringify(response));
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Which methods a remote side may call. */
|
|
2
|
+
export namespace RpcMethodUtil {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Whether `method` is a method of `target` declared by its class or a superclass other than
|
|
6
|
+
* `Object`: not `constructor`, not inherited from `Object.prototype` (`toString`, `__proto__`...).
|
|
7
|
+
*/
|
|
8
|
+
export function callable(target: object, method: string): boolean {
|
|
9
|
+
if (method === 'constructor' || method.startsWith('__')) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
for (let proto = Object.getPrototypeOf(target); proto && proto !== Object.prototype; proto = Object.getPrototypeOf(proto)) {
|
|
13
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, method);
|
|
14
|
+
if (descriptor) {
|
|
15
|
+
return typeof descriptor.value === 'function';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return Object.prototype.hasOwnProperty.call(target, method) && typeof (target as Record<string, unknown>)[method] === 'function';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** `GreetingServer/greet` → `['GreetingServer', 'greet']`. */
|
|
22
|
+
export function split(qualified: string): [string, string] | undefined {
|
|
23
|
+
const index = qualified.lastIndexOf('/');
|
|
24
|
+
return index > 0 && index < qualified.length - 1 ? [qualified.slice(0, index), qualified.slice(index + 1)] : undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,46 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ID_KEY, RPC } from '../annotation';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
let defaultProxyCreator: ProxyCreator | undefined;
|
|
1
|
+
import { ComponentId, ContainerUtil, UrlUtil } from '@celljs/core';
|
|
2
|
+
import { ID_KEY, RPC } from '../annotation/autorpc';
|
|
3
|
+
import { HttpTransport, HttpTransportOptions } from '../transport/http-transport';
|
|
4
|
+
import { RpcProxy } from '../proxy/rpc-proxy';
|
|
7
5
|
|
|
8
6
|
export namespace RpcUtil {
|
|
9
|
-
export function get<T extends object>(rpcServiceIdentifier: ComponentId<T>): T {
|
|
10
|
-
if (defaultProxyCreator) {
|
|
11
|
-
return defaultProxyCreator.create<T>(toPath(rpcServiceIdentifier));
|
|
12
|
-
}
|
|
13
|
-
return ContainerUtil.get(RPC, { tags: { [ID_KEY]: rpcServiceIdentifier } });
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getDefaultProxyCreator(endpoint: string, options?: Partial<HttpProxyCreatorOptions<Partial<MergeOptions>>>) {
|
|
17
|
-
return defaultProxyCreator;
|
|
18
|
-
}
|
|
19
7
|
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
/** The proxy of a service from the application's container (as `@Autorpc(id)` injects it). */
|
|
9
|
+
export function get<T extends object>(id: ComponentId<T>): T {
|
|
10
|
+
return ContainerUtil.get(RPC, { tags: { [ID_KEY]: id } });
|
|
22
11
|
}
|
|
23
12
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}
|
|
13
|
+
/** A proxy of the service `id` at `endpoint` (the URL of `rpc.path`), over HTTP, without the container. */
|
|
14
|
+
export function create<T extends object>(endpoint: string, id: ComponentId<T>, options: Partial<HttpTransportOptions> = {}): T {
|
|
15
|
+
const transport = new HttpTransport({
|
|
16
|
+
...options,
|
|
17
|
+
endpointResolver: options.endpointResolver ?? { resolve: async service => UrlUtil.join(endpoint, service) },
|
|
18
|
+
});
|
|
19
|
+
return RpcProxy.create<T>(toPath(id), transport);
|
|
30
20
|
}
|
|
31
21
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return typeof
|
|
39
|
-
|
|
22
|
+
/** The path of a service: the description of a symbol, the string, or the name of a class. */
|
|
23
|
+
export function toPath(id: ComponentId): string {
|
|
24
|
+
if (typeof id === 'symbol') {
|
|
25
|
+
// Symbol(GreetingServer) → GreetingServer
|
|
26
|
+
return id.toString().slice(7, -1);
|
|
27
|
+
}
|
|
28
|
+
return typeof id === 'function' ? id.name : String(id);
|
|
40
29
|
}
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
/** The name an `ErrorConverter` of the service is bound with. */
|
|
32
|
+
export function toName(id: ComponentId): string | symbol {
|
|
33
|
+
return typeof id === 'function' ? id.name : (id as string | symbol);
|
|
45
34
|
}
|
|
46
35
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ComponentId, Disposable, Event } from '@celljs/core';
|
|
2
|
+
import type { Request } from '@celljs/web/lib/node';
|
|
3
|
+
|
|
4
|
+
export const RPC_CONNECTION_KEY = 'RpcConnection';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A WebSocket connection of a client (`rpc.transport: websocket`). Calls that come over it run with
|
|
8
|
+
* it in their context (`RpcContext.connection()`), and the server calls the client's `@RpcClient`
|
|
9
|
+
* components through it.
|
|
10
|
+
*/
|
|
11
|
+
export interface RpcConnection {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/** The upgrade request: headers, cookies and address of the client. */
|
|
14
|
+
readonly request: Request;
|
|
15
|
+
readonly closed: boolean;
|
|
16
|
+
/** A proxy of the client's `@RpcClient(id)`; its calls reject once the connection is closed. */
|
|
17
|
+
client<T extends object>(id: ComponentId<T>): T;
|
|
18
|
+
onClose(listener: () => void): Disposable;
|
|
19
|
+
close(code?: number, reason?: string): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const RpcConnectionManager = Symbol('RpcConnectionManager');
|
|
23
|
+
|
|
24
|
+
/** The open connections, to push to all of them or find one. */
|
|
25
|
+
export interface RpcConnectionManager {
|
|
26
|
+
readonly connections: readonly RpcConnection[];
|
|
27
|
+
readonly onConnect: Event<RpcConnection>;
|
|
28
|
+
add(connection: RpcConnection): void;
|
|
29
|
+
closeAll(code?: number, reason?: string): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Component, Emitter, Event } from '@celljs/core';
|
|
2
|
+
import { RpcConnection, RpcConnectionManager } from './connection-protocol';
|
|
3
|
+
|
|
4
|
+
@Component(RpcConnectionManager)
|
|
5
|
+
export class RpcConnectionManagerImpl implements RpcConnectionManager {
|
|
6
|
+
|
|
7
|
+
protected readonly open = new Set<RpcConnection>();
|
|
8
|
+
protected readonly onConnectEmitter = new Emitter<RpcConnection>();
|
|
9
|
+
|
|
10
|
+
get connections(): readonly RpcConnection[] {
|
|
11
|
+
return [...this.open];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get onConnect(): Event<RpcConnection> {
|
|
15
|
+
return this.onConnectEmitter.event;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
add(connection: RpcConnection): void {
|
|
19
|
+
this.open.add(connection);
|
|
20
|
+
connection.onClose(() => this.open.delete(connection));
|
|
21
|
+
this.onConnectEmitter.fire(connection);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
closeAll(code = 1001, reason = 'The server is stopping.'): void {
|
|
25
|
+
for (const connection of [...this.open]) {
|
|
26
|
+
connection.close(code, reason);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|