@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
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { HttpHeaders, HttpMethod, MediaType, XML_HTTP_REQUEST, RestOperations, DefaultRestOperationsFactory } from '@celljs/http';
|
|
2
|
-
import { Logger } from 'vscode-jsonrpc';
|
|
3
|
-
import { ProxyCreator, ConnectionOptions, RequestTaskMeta } from './proxy-protocol';
|
|
4
|
-
import { EndpointResolver } from '../endpoint';
|
|
5
|
-
import { ConnnectionFactory, ConnnectionFactoryImpl, JsonRpcProxy, JsonRpcProxyFactory } from '../factory';
|
|
6
|
-
import { Channel, HttpChannel } from '../channal';
|
|
7
|
-
import { ErrorConverter } from '../converter';
|
|
8
|
-
import { ConnectionHandler } from '../handler';
|
|
9
|
-
import { AxiosRequestConfig } from 'axios';
|
|
10
|
-
import { ClientConfigProcessor } from '../processor';
|
|
11
|
-
import { ConsoleLogger } from '../utils';
|
|
12
|
-
|
|
13
|
-
export interface MergeOptions {
|
|
14
|
-
maxCount: number;
|
|
15
|
-
maxLength: number;
|
|
16
|
-
timerDelay: number;
|
|
17
|
-
enabled: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface HttpProxyCreatorOptions<T> {
|
|
21
|
-
|
|
22
|
-
connnectionFactory: ConnnectionFactory<Channel>;
|
|
23
|
-
endpointResolver: EndpointResolver;
|
|
24
|
-
restOperations: RestOperations;
|
|
25
|
-
clientConfigProcessor?: ClientConfigProcessor;
|
|
26
|
-
clientConfig: AxiosRequestConfig;
|
|
27
|
-
merge: T;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const DEFAULT_OPTIONS: Omit<HttpProxyCreatorOptions<MergeOptions>, 'endpointResolver'> = {
|
|
31
|
-
connnectionFactory: new ConnnectionFactoryImpl(),
|
|
32
|
-
restOperations: new DefaultRestOperationsFactory().create(),
|
|
33
|
-
clientConfig: {},
|
|
34
|
-
merge: {
|
|
35
|
-
maxCount: 100,
|
|
36
|
-
maxLength: 5242880,
|
|
37
|
-
timerDelay: 35,
|
|
38
|
-
enabled: false
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export class HttpProxyCreator implements ProxyCreator {
|
|
44
|
-
|
|
45
|
-
protected channelIdSeq = 0;
|
|
46
|
-
|
|
47
|
-
protected requestMap = new Map<string, RequestTaskMeta>();
|
|
48
|
-
protected channelMap = new Map<number, Channel>();
|
|
49
|
-
protected options: HttpProxyCreatorOptions<MergeOptions>;
|
|
50
|
-
|
|
51
|
-
constructor(
|
|
52
|
-
options: Partial<Omit<HttpProxyCreatorOptions<Partial<MergeOptions>>, 'endpointResolver'>> & Pick<HttpProxyCreatorOptions<Partial<MergeOptions>>, 'endpointResolver'>) {
|
|
53
|
-
this.options = { ...DEFAULT_OPTIONS, ...options, merge: { ...DEFAULT_OPTIONS.merge, ...options.merge } };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
create<T extends object>(path: string, errorConverters?: ErrorConverter[], target?: object | undefined): JsonRpcProxy<T> {
|
|
57
|
-
const factory = new JsonRpcProxyFactory<T>(target, errorConverters);
|
|
58
|
-
this.options.endpointResolver.resolve(path).then(endpoint => this.listen({
|
|
59
|
-
path: endpoint,
|
|
60
|
-
onConnection: c => factory.listen(c)
|
|
61
|
-
}));
|
|
62
|
-
return factory.createProxy();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
support(path: string): number {
|
|
66
|
-
return 500;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
listen(handler: ConnectionHandler, options?: ConnectionOptions): void {
|
|
70
|
-
this.openChannel(handler.path, channel => {
|
|
71
|
-
const connection = this.options.connnectionFactory.create(channel, this.createLogger());
|
|
72
|
-
handler.onConnection(connection);
|
|
73
|
-
}, options);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
openChannel(path: string, handler: (channel: Channel) => void, options?: ConnectionOptions): void {
|
|
77
|
-
this.doOpenChannel(path, handler, options);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
protected doOpenChannel(path: string, handler: (channel: Channel) => void, options?: ConnectionOptions): void {
|
|
81
|
-
const id = this.channelIdSeq++;
|
|
82
|
-
const channel = this.createChannel(id, path);
|
|
83
|
-
handler(channel);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
protected createChannel(id: number, path: string): Channel {
|
|
87
|
-
const parts = path.split('/');
|
|
88
|
-
const serviceName = parts.pop();
|
|
89
|
-
const endpoint = parts.join('/');
|
|
90
|
-
const channel = new HttpChannel(id, async content => {
|
|
91
|
-
if (this.options.merge.enabled) {
|
|
92
|
-
if (this.canMerge(endpoint, content)) {
|
|
93
|
-
this.pushContent(endpoint, content);
|
|
94
|
-
} else {
|
|
95
|
-
this.executeTask(endpoint);
|
|
96
|
-
this.pushContent(endpoint, content);
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
this.pushContent(endpoint, content);
|
|
100
|
-
this.executeTask(endpoint);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
}, serviceName);
|
|
104
|
-
this.channelMap.set(id, channel);
|
|
105
|
-
return channel;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
protected executeTask(endpoint: string) {
|
|
109
|
-
const meta = this.requestMap.get(endpoint);
|
|
110
|
-
if (meta) {
|
|
111
|
-
return meta.task();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
protected canMerge(endpoint: string, content: string) {
|
|
116
|
-
const meta = this.requestMap.get(endpoint);
|
|
117
|
-
if (meta) {
|
|
118
|
-
if (meta.contentLength + content.length > this.options.merge.maxLength ||
|
|
119
|
-
meta.contents.length + 1 > this.options.merge.maxCount) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
protected pushContent(endpoint: string, content: string) {
|
|
127
|
-
let meta = this.requestMap.get(endpoint);
|
|
128
|
-
if (!meta) {
|
|
129
|
-
const task = this.createTask(endpoint);
|
|
130
|
-
meta = {
|
|
131
|
-
id: setTimeout(task, this.options.merge.timerDelay),
|
|
132
|
-
contents: [],
|
|
133
|
-
contentLength: 0,
|
|
134
|
-
task
|
|
135
|
-
};
|
|
136
|
-
this.requestMap.set(endpoint, meta);
|
|
137
|
-
}
|
|
138
|
-
meta.contents.push(content);
|
|
139
|
-
meta.contentLength += content.length;
|
|
140
|
-
return meta;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
protected createTask(endpoint: string) {
|
|
144
|
-
return async () => {
|
|
145
|
-
const meta = this.requestMap.get(endpoint);
|
|
146
|
-
if (!meta) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
clearTimeout(meta.id as any);
|
|
150
|
-
const contents = meta.contents;
|
|
151
|
-
this.requestMap.delete(endpoint);
|
|
152
|
-
const config: AxiosRequestConfig = {
|
|
153
|
-
url: endpoint,
|
|
154
|
-
method: HttpMethod.POST,
|
|
155
|
-
data: contents.length > 1 ? JSON.stringify(contents) : contents[0],
|
|
156
|
-
headers: {
|
|
157
|
-
[HttpHeaders.CONTENT_TYPE]: MediaType.APPLICATION_JSON_UTF8,
|
|
158
|
-
[HttpHeaders.X_REQUESTED_WITH]: XML_HTTP_REQUEST
|
|
159
|
-
},
|
|
160
|
-
...this.options.clientConfig
|
|
161
|
-
};
|
|
162
|
-
await this.options.clientConfigProcessor?.process(config);
|
|
163
|
-
const { data } = await this.options.restOperations.request(config);
|
|
164
|
-
if (Array.isArray(data)) {
|
|
165
|
-
for (const message of data) {
|
|
166
|
-
const parsed = JSON.parse(message);
|
|
167
|
-
this.channelMap.get(parsed.id)!.handleMessage(parsed);
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
this.channelMap.get(data.id)!.handleMessage(data);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
protected createLogger(): Logger {
|
|
176
|
-
return new ConsoleLogger();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ErrorConverter } from '../converter';
|
|
2
|
-
import { JsonRpcProxy } from '../factory';
|
|
3
|
-
|
|
4
|
-
export const ProxyProvider = Symbol('ProxyProvider');
|
|
5
|
-
|
|
6
|
-
export interface ProxyProvider {
|
|
7
|
-
provide<T extends object>(path: string, errorConverters?: ErrorConverter[], target?: object): JsonRpcProxy<T>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const ProxyCreator = Symbol('ProxyCreator');
|
|
11
|
-
|
|
12
|
-
export interface ProxyCreator {
|
|
13
|
-
create<T extends object>(path: string, errorConverters?: ErrorConverter[], target?: object): JsonRpcProxy<T>;
|
|
14
|
-
support(path: string): number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ConnectionOptions {
|
|
18
|
-
reconnecting?: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface RequestTaskMeta {
|
|
22
|
-
id: number | NodeJS.Timeout;
|
|
23
|
-
contentLength: number;
|
|
24
|
-
contents: string[];
|
|
25
|
-
task: () => Promise<void>;
|
|
26
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Prioritizeable, Component, Autowired } from '@celljs/core';
|
|
2
|
-
import { ErrorConverter } from '../converter';
|
|
3
|
-
import { JsonRpcProxy } from '../factory';
|
|
4
|
-
import { ProxyProvider, ProxyCreator } from './proxy-protocol';
|
|
5
|
-
|
|
6
|
-
@Component(ProxyProvider)
|
|
7
|
-
export class ProxyProviderImpl implements ProxyProvider {
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
@Autowired(ProxyCreator)
|
|
11
|
-
protected readonly proxyCreators: ProxyCreator[]
|
|
12
|
-
) { }
|
|
13
|
-
|
|
14
|
-
provide<T extends object>(path: string, errorConverters?: ErrorConverter[], target?: object): JsonRpcProxy<T> {
|
|
15
|
-
return this.prioritize(path)[0].create(path, errorConverters, target);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
protected prioritize(path: string): ProxyCreator[] {
|
|
19
|
-
const prioritized = Prioritizeable.prioritizeAllSync(this.proxyCreators, proxyCreator => {
|
|
20
|
-
try {
|
|
21
|
-
return proxyCreator.support(path);
|
|
22
|
-
} catch {
|
|
23
|
-
return 0;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return prioritized.map(p => p.value);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Logger as ILoger } from 'vscode-jsonrpc';
|
|
2
|
-
|
|
3
|
-
export class ConsoleLogger implements ILoger {
|
|
4
|
-
public error(message: string): void {
|
|
5
|
-
console.error(message);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
public warn(message: string): void {
|
|
9
|
-
console.warn(message);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public info(message: string): void {
|
|
13
|
-
console.info(message);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public log(message: string): void {
|
|
17
|
-
console.log(message);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public debug(message: string): void {
|
|
21
|
-
console.debug(message);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Context, NotFoundError } from '@celljs/web/lib/node';
|
|
2
|
-
import { ConnectionHandler, ConnnectionFactory, Channel, ConsoleLogger } from '../../common';
|
|
3
|
-
import { Component, Autowired, Deferred, Optional } from '@celljs/core';
|
|
4
|
-
import { CURRENT_CHANNEL_STRATEGY_REQUEST_KEY, ChannelStrategy } from './channel-protocol';
|
|
5
|
-
|
|
6
|
-
// tslint:disable:no-any
|
|
7
|
-
@Component()
|
|
8
|
-
export class ChannelManager {
|
|
9
|
-
|
|
10
|
-
protected _handlers = new Map<string, ConnectionHandler>();
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
@Autowired(ConnectionHandler) @Optional()
|
|
14
|
-
protected readonly handlers: ConnectionHandler[],
|
|
15
|
-
@Autowired(ConnnectionFactory) protected connnectionFactory: ConnnectionFactory<Channel>
|
|
16
|
-
) {
|
|
17
|
-
for (const handler of handlers) {
|
|
18
|
-
this._handlers.set(handler.path, handler);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async handleChannels(): Promise<void> {
|
|
23
|
-
const channelStrategy: ChannelStrategy = Context.getAttr(CURRENT_CHANNEL_STRATEGY_REQUEST_KEY);
|
|
24
|
-
Context.getResponse().body = new Deferred<any>();
|
|
25
|
-
for (const message of await channelStrategy.getMessages()) {
|
|
26
|
-
const { id, path } = message as any;
|
|
27
|
-
if (path) {
|
|
28
|
-
const handler = this._handlers.get(this.getRealPath(path));
|
|
29
|
-
if (handler) {
|
|
30
|
-
const channel = await channelStrategy.createChannel(id);
|
|
31
|
-
handler.onConnection(this.connnectionFactory.create(channel, new ConsoleLogger()));
|
|
32
|
-
channel.handleMessage(message);
|
|
33
|
-
}
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
throw new NotFoundError(`Cannot find a service for the path: ${path}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected getRealPath(path: string): string {
|
|
41
|
-
return <string>path.split(':').pop();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Middleware, Context } from '@celljs/web/lib/node';
|
|
2
|
-
import { Component, Autowired } from '@celljs/core';
|
|
3
|
-
import { ChannelStrategy, CHANNEL_MIDDLEWARE_PRIORITY, CURRENT_CHANNEL_STRATEGY_REQUEST_KEY } from './channel-protocol';
|
|
4
|
-
import { HttpHeaders, MediaType } from '@celljs/http';
|
|
5
|
-
|
|
6
|
-
@Component(Middleware)
|
|
7
|
-
export class ChannelMiddleware implements Middleware {
|
|
8
|
-
|
|
9
|
-
@Autowired(ChannelStrategy)
|
|
10
|
-
protected readonly channelStrategies: ChannelStrategy[];
|
|
11
|
-
|
|
12
|
-
async handle(ctx: Context, next: () => Promise<void>): Promise<void> {
|
|
13
|
-
for (const channelStrategy of this.channelStrategies) {
|
|
14
|
-
if (await channelStrategy.support()) {
|
|
15
|
-
Context.setAttr(CURRENT_CHANNEL_STRATEGY_REQUEST_KEY, channelStrategy);
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
ctx.response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8);
|
|
21
|
-
|
|
22
|
-
await next();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
readonly priority = CHANNEL_MIDDLEWARE_PRIORITY;
|
|
26
|
-
|
|
27
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Channel } from '../../common';
|
|
2
|
-
|
|
3
|
-
export const ChannelStrategy = Symbol('ChannelStrategy');
|
|
4
|
-
|
|
5
|
-
export const CHANNEL_MIDDLEWARE_PRIORITY = 2100;
|
|
6
|
-
|
|
7
|
-
export const CURRENT_CHANNEL_STRATEGY_REQUEST_KEY = 'CurrentChannelStrategyRequest';
|
|
8
|
-
export const CURRENT_MESSAGE_COUNT_REQUEST_KEY = 'CurrentMessageCountRequest';
|
|
9
|
-
export const CURRENT_RESPONSE_MESSAGE_REQUEST_KEY = 'CurrentResponseMessageRequest';
|
|
10
|
-
|
|
11
|
-
export interface ChannelStrategy {
|
|
12
|
-
|
|
13
|
-
getMessages(): Promise<Channel.Message[]>;
|
|
14
|
-
|
|
15
|
-
handleMessage(message: any): Promise<void>;
|
|
16
|
-
|
|
17
|
-
createChannel(id: number): Promise<Channel>
|
|
18
|
-
|
|
19
|
-
support(): Promise<boolean>;
|
|
20
|
-
|
|
21
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Channel, HttpChannel } from '../../common/channal';
|
|
2
|
-
import { ChannelStrategy, CURRENT_MESSAGE_COUNT_REQUEST_KEY, CURRENT_RESPONSE_MESSAGE_REQUEST_KEY } from './channel-protocol';
|
|
3
|
-
import { Component } from '@celljs/core';
|
|
4
|
-
import { Context } from '@celljs/web/lib/node';
|
|
5
|
-
|
|
6
|
-
@Component(ChannelStrategy)
|
|
7
|
-
export class HttpChannelStrategy implements ChannelStrategy {
|
|
8
|
-
async getMessages(): Promise<Channel.Message[]> {
|
|
9
|
-
let message = await Context.getRequest().body;
|
|
10
|
-
if (!Array.isArray(message)) {
|
|
11
|
-
message = [ message ];
|
|
12
|
-
} else {
|
|
13
|
-
const parsed: Channel.Message[] = [];
|
|
14
|
-
for (const m of message) {
|
|
15
|
-
parsed.push(JSON.parse(m));
|
|
16
|
-
}
|
|
17
|
-
message = parsed;
|
|
18
|
-
}
|
|
19
|
-
Context.setAttr(CURRENT_MESSAGE_COUNT_REQUEST_KEY, message.length);
|
|
20
|
-
return message;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async createChannel(id: number): Promise<Channel> {
|
|
24
|
-
return new HttpChannel(id, async content => {
|
|
25
|
-
this.handleMessage(content);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async handleMessage(message: string): Promise<void> {
|
|
30
|
-
if (!this.consumeMessage(message)) {
|
|
31
|
-
const deferred = Context.getResponse().body;
|
|
32
|
-
const messages = Context.getAttr<string[]>(CURRENT_RESPONSE_MESSAGE_REQUEST_KEY);
|
|
33
|
-
deferred.resolve(messages.length > 1 ? JSON.stringify(messages) : message);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected consumeMessage(message: string) {
|
|
38
|
-
const messageCount = Context.getAttr<number>(CURRENT_MESSAGE_COUNT_REQUEST_KEY);
|
|
39
|
-
Context.setAttr(CURRENT_MESSAGE_COUNT_REQUEST_KEY, messageCount - 1);
|
|
40
|
-
let messages = Context.getAttr<string[]>(CURRENT_RESPONSE_MESSAGE_REQUEST_KEY);
|
|
41
|
-
if (!messages) {
|
|
42
|
-
messages = [];
|
|
43
|
-
Context.setAttr(CURRENT_RESPONSE_MESSAGE_REQUEST_KEY, messages);
|
|
44
|
-
}
|
|
45
|
-
messages.push(message);
|
|
46
|
-
if (messageCount - 1 <= 0) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async support(): Promise<boolean> {
|
|
53
|
-
return Context.getCurrent() instanceof Context;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Component, Autowired, Value, Deferred } from '@celljs/core';
|
|
2
|
-
import { ChannelManager } from '../channel';
|
|
3
|
-
import { RPC_HANDLER_ADAPTER_PRIORITY } from './handler-protocol';
|
|
4
|
-
import { RequestMatcher, HandlerAdapter, Context } from '@celljs/web/lib/node';
|
|
5
|
-
import { PathResolver } from '@celljs/web';
|
|
6
|
-
import { RPC_PATH } from '../../common';
|
|
7
|
-
|
|
8
|
-
export const PATH_PARMAS_ATTR = 'pathParams';
|
|
9
|
-
|
|
10
|
-
@Component(HandlerAdapter)
|
|
11
|
-
export class RpcHandlerAdapter implements HandlerAdapter {
|
|
12
|
-
readonly priority = RPC_HANDLER_ADAPTER_PRIORITY;
|
|
13
|
-
|
|
14
|
-
@Autowired(ChannelManager)
|
|
15
|
-
protected readonly channelManager: ChannelManager;
|
|
16
|
-
|
|
17
|
-
@Autowired(RequestMatcher)
|
|
18
|
-
protected readonly requestMatcher: RequestMatcher;
|
|
19
|
-
|
|
20
|
-
@Autowired(PathResolver)
|
|
21
|
-
protected readonly pathResolver: PathResolver;
|
|
22
|
-
|
|
23
|
-
@Value(RPC_PATH)
|
|
24
|
-
protected readonly rpcPath: string;
|
|
25
|
-
|
|
26
|
-
async handle(): Promise<void> {
|
|
27
|
-
await this.channelManager.handleChannels();
|
|
28
|
-
const response = Context.getResponse();
|
|
29
|
-
if (response.body instanceof Deferred) {
|
|
30
|
-
response.body = await response.body.promise;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async canHandle(): Promise<boolean> {
|
|
35
|
-
return this.requestMatcher.match(await this.pathResolver.resolve(this.rpcPath));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const RPC_HANDLER_ADAPTER_PRIORITY = 1000;
|