@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,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const websocket_frames_1 = require("./websocket-frames");
|
|
5
|
+
/** A frame as a client sends it: masked. */
|
|
6
|
+
function clientFrame(opcode, payload, fin = true) {
|
|
7
|
+
const plain = websocket_frames_1.WebSocketFrames.encode(opcode, payload);
|
|
8
|
+
const headerLength = plain.length - payload.length;
|
|
9
|
+
const mask = Buffer.from([1, 2, 3, 4]);
|
|
10
|
+
const header = Buffer.from(plain.subarray(0, headerLength));
|
|
11
|
+
header[0] = (fin ? 0x80 : 0) | opcode;
|
|
12
|
+
header[1] |= 0x80;
|
|
13
|
+
const masked = Buffer.from(payload.map((b, i) => b ^ mask[i & 3]));
|
|
14
|
+
return Buffer.concat([header, mask, masked]);
|
|
15
|
+
}
|
|
16
|
+
function protocolError(fn) {
|
|
17
|
+
try {
|
|
18
|
+
fn();
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return error;
|
|
22
|
+
}
|
|
23
|
+
throw new Error('expected a WebSocketProtocolError');
|
|
24
|
+
}
|
|
25
|
+
(0, bun_test_1.describe)('WebSocketFrames', () => {
|
|
26
|
+
(0, bun_test_1.it)('encodes payloads of 7-, 16- and 64-bit lengths, unmasked', () => {
|
|
27
|
+
(0, bun_test_1.expect)([...websocket_frames_1.WebSocketFrames.encode(websocket_frames_1.WebSocketFrames.TEXT, Buffer.from('hi'))]).toEqual([0x81, 2, 0x68, 0x69]);
|
|
28
|
+
(0, bun_test_1.expect)(websocket_frames_1.WebSocketFrames.encode(websocket_frames_1.WebSocketFrames.TEXT, Buffer.alloc(300)).subarray(0, 4)).toEqual(Buffer.from([0x81, 126, 1, 44]));
|
|
29
|
+
(0, bun_test_1.expect)(websocket_frames_1.WebSocketFrames.encode(websocket_frames_1.WebSocketFrames.TEXT, Buffer.alloc(70000)).subarray(0, 10)).toEqual(Buffer.from([0x81, 127, 0, 0, 0, 0, 0, 1, 0x11, 0x70]));
|
|
30
|
+
});
|
|
31
|
+
(0, bun_test_1.it)('parses masked frames of every length, also when they arrive in pieces', () => {
|
|
32
|
+
const parser = new websocket_frames_1.WebSocketFrameParser(1 << 20);
|
|
33
|
+
for (const size of [0, 125, 126, 65535, 65536]) {
|
|
34
|
+
const payload = Buffer.alloc(size, 7);
|
|
35
|
+
const bytes = clientFrame(websocket_frames_1.WebSocketFrames.TEXT, payload);
|
|
36
|
+
const frames = [...parser.push(bytes.subarray(0, 3)), ...parser.push(bytes.subarray(3))];
|
|
37
|
+
(0, bun_test_1.expect)(frames.length).toBe(1);
|
|
38
|
+
(0, bun_test_1.expect)(frames[0].payload.equals(payload)).toBe(true);
|
|
39
|
+
}
|
|
40
|
+
const two = Buffer.concat([clientFrame(websocket_frames_1.WebSocketFrames.TEXT, Buffer.from('a'), false), clientFrame(websocket_frames_1.WebSocketFrames.CONTINUATION, Buffer.from('b'))]);
|
|
41
|
+
(0, bun_test_1.expect)(parser.push(two).map(f => [f.opcode, f.fin, f.payload.toString()])).toEqual([[1, false, 'a'], [0, true, 'b']]);
|
|
42
|
+
});
|
|
43
|
+
(0, bun_test_1.it)('refuses unmasked frames, reserved bits, unknown opcodes, large control frames and too large messages', () => {
|
|
44
|
+
const parser = () => new websocket_frames_1.WebSocketFrameParser(1000);
|
|
45
|
+
(0, bun_test_1.expect)(protocolError(() => parser().push(websocket_frames_1.WebSocketFrames.encode(websocket_frames_1.WebSocketFrames.TEXT, Buffer.from('x')))).code).toBe(1002);
|
|
46
|
+
const reserved = clientFrame(websocket_frames_1.WebSocketFrames.TEXT, Buffer.from('x'));
|
|
47
|
+
reserved[0] |= 0x40;
|
|
48
|
+
(0, bun_test_1.expect)(protocolError(() => parser().push(reserved)).code).toBe(1002);
|
|
49
|
+
const unknown = clientFrame(websocket_frames_1.WebSocketFrames.TEXT, Buffer.from('x'));
|
|
50
|
+
unknown[0] = 0x83;
|
|
51
|
+
(0, bun_test_1.expect)(protocolError(() => parser().push(unknown)).code).toBe(1002);
|
|
52
|
+
(0, bun_test_1.expect)(protocolError(() => parser().push(clientFrame(websocket_frames_1.WebSocketFrames.PING, Buffer.alloc(126)))).code).toBe(1002);
|
|
53
|
+
(0, bun_test_1.expect)(protocolError(() => parser().push(clientFrame(websocket_frames_1.WebSocketFrames.TEXT, Buffer.alloc(1001)))).code).toBe(1009);
|
|
54
|
+
});
|
|
55
|
+
(0, bun_test_1.it)('writes the code and reason of a close frame', () => {
|
|
56
|
+
(0, bun_test_1.expect)([...websocket_frames_1.WebSocketFrames.closePayload(1001, 'bye')]).toEqual([3, 233, 98, 121, 101]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=websocket-frames.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-frames.spec.js","sourceRoot":"","sources":["../../../src/node/websocket/websocket-frames.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,yDAAmG;AAEnG,4CAA4C;AAC5C,SAAS,WAAW,CAAC,MAAc,EAAE,OAAe,EAAE,GAAG,GAAG,IAAI;IAC5D,MAAM,KAAK,GAAG,kCAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;IAC5D,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IACtC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAClB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,aAAa,CAAC,EAAiB;IACpC,IAAI,CAAC;QACD,EAAE,EAAE,CAAC;IACT,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,KAA+B,CAAC;IAC3C,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;AACzD,CAAC;AAED,IAAA,mBAAQ,EAAC,iBAAiB,EAAE,GAAG,EAAE;IAE7B,IAAA,aAAE,EAAC,0DAA0D,EAAE,GAAG,EAAE;QAChE,IAAA,iBAAM,EAAC,CAAC,GAAG,kCAAe,CAAC,MAAM,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QAC5G,IAAA,iBAAM,EAAC,kCAAe,CAAC,MAAM,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAChI,IAAA,iBAAM,EAAC,kCAAe,CAAC,MAAM,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9J,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,uEAAuE,EAAE,GAAG,EAAE;QAC7E,MAAM,MAAM,GAAG,IAAI,uCAAoB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACjD,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC;YAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YACtC,MAAM,KAAK,GAAG,WAAW,CAAC,kCAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACzD,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACzF,IAAA,iBAAM,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAA,iBAAM,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,kCAAe,CAAC,YAAY,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACrJ,IAAA,iBAAM,EAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1H,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,sGAAsG,EAAE,GAAG,EAAE;QAC5G,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,uCAAoB,CAAC,IAAI,CAAC,CAAC;QACpD,IAAA,iBAAM,EAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,kCAAe,CAAC,MAAM,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3H,MAAM,QAAQ,GAAG,WAAW,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACrE,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QACpB,IAAA,iBAAM,EAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrE,MAAM,OAAO,GAAG,WAAW,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACpE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QAClB,IAAA,iBAAM,EAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpE,IAAA,iBAAM,EAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjH,IAAA,iBAAM,EAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,kCAAe,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtH,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,6CAA6C,EAAE,GAAG,EAAE;QACnD,IAAA,iBAAM,EAAC,CAAC,GAAG,kCAAe,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3F,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/rpc",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "4.4.0",
|
|
4
|
+
"description": "Typed JSON-RPC between the frontend and backends of Cell applications, over HTTP or WebSocket",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
7
7
|
],
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"lib",
|
|
24
24
|
"esm",
|
|
25
25
|
"src",
|
|
26
|
-
"cell.yml"
|
|
26
|
+
"cell.yml",
|
|
27
|
+
"cell.schema.json"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "tsc -b && bun ../../scripts/build-esm.ts",
|
|
@@ -32,11 +33,9 @@
|
|
|
32
33
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@celljs/core": "4.
|
|
36
|
-
"@celljs/http": "4.
|
|
37
|
-
"@celljs/web": "4.
|
|
38
|
-
"axios": "^0.35.0",
|
|
39
|
-
"vscode-jsonrpc": "^6.0.0"
|
|
36
|
+
"@celljs/core": "4.4.0",
|
|
37
|
+
"@celljs/http": "4.4.0",
|
|
38
|
+
"@celljs/web": "4.4.0"
|
|
40
39
|
},
|
|
41
40
|
"publishConfig": {
|
|
42
41
|
"access": "public"
|
|
@@ -59,9 +58,9 @@
|
|
|
59
58
|
"import": "./esm/common/annotation/detached/index.js",
|
|
60
59
|
"default": "./lib/common/annotation/detached/index.js"
|
|
61
60
|
},
|
|
62
|
-
"./lib/common/
|
|
63
|
-
"import": "./esm/common/
|
|
64
|
-
"default": "./lib/common/
|
|
61
|
+
"./lib/common/client": {
|
|
62
|
+
"import": "./esm/common/client/index.js",
|
|
63
|
+
"default": "./lib/common/client/index.js"
|
|
65
64
|
},
|
|
66
65
|
"./lib/common/converter": {
|
|
67
66
|
"import": "./esm/common/converter/index.js",
|
|
@@ -75,22 +74,22 @@
|
|
|
75
74
|
"import": "./esm/common/error/index.js",
|
|
76
75
|
"default": "./lib/common/error/index.js"
|
|
77
76
|
},
|
|
78
|
-
"./lib/common/factory": {
|
|
79
|
-
"import": "./esm/common/factory/index.js",
|
|
80
|
-
"default": "./lib/common/factory/index.js"
|
|
81
|
-
},
|
|
82
|
-
"./lib/common/handler": {
|
|
83
|
-
"import": "./esm/common/handler/index.js",
|
|
84
|
-
"default": "./lib/common/handler/index.js"
|
|
85
|
-
},
|
|
86
77
|
"./lib/common/processor": {
|
|
87
78
|
"import": "./esm/common/processor/index.js",
|
|
88
79
|
"default": "./lib/common/processor/index.js"
|
|
89
80
|
},
|
|
81
|
+
"./lib/common/protocol": {
|
|
82
|
+
"import": "./esm/common/protocol/index.js",
|
|
83
|
+
"default": "./lib/common/protocol/index.js"
|
|
84
|
+
},
|
|
90
85
|
"./lib/common/proxy": {
|
|
91
86
|
"import": "./esm/common/proxy/index.js",
|
|
92
87
|
"default": "./lib/common/proxy/index.js"
|
|
93
88
|
},
|
|
89
|
+
"./lib/common/transport": {
|
|
90
|
+
"import": "./esm/common/transport/index.js",
|
|
91
|
+
"default": "./lib/common/transport/index.js"
|
|
92
|
+
},
|
|
94
93
|
"./lib/common/utils": {
|
|
95
94
|
"import": "./esm/common/utils/index.js",
|
|
96
95
|
"default": "./lib/common/utils/index.js"
|
|
@@ -99,13 +98,17 @@
|
|
|
99
98
|
"import": "./esm/node/index.js",
|
|
100
99
|
"default": "./lib/node/index.js"
|
|
101
100
|
},
|
|
102
|
-
"./lib/node/
|
|
103
|
-
"import": "./esm/node/
|
|
104
|
-
"default": "./lib/node/
|
|
101
|
+
"./lib/node/connection": {
|
|
102
|
+
"import": "./esm/node/connection/index.js",
|
|
103
|
+
"default": "./lib/node/connection/index.js"
|
|
104
|
+
},
|
|
105
|
+
"./lib/node/server": {
|
|
106
|
+
"import": "./esm/node/server/index.js",
|
|
107
|
+
"default": "./lib/node/server/index.js"
|
|
105
108
|
},
|
|
106
|
-
"./lib/node/
|
|
107
|
-
"import": "./esm/node/
|
|
108
|
-
"default": "./lib/node/
|
|
109
|
+
"./lib/node/websocket": {
|
|
110
|
+
"import": "./esm/node/websocket/index.js",
|
|
111
|
+
"default": "./lib/node/websocket/index.js"
|
|
109
112
|
},
|
|
110
113
|
"./lib/*.js": {
|
|
111
114
|
"import": "./esm/*.js",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentDecorator, applyComponentDecorator, parseComponentOption } from '@celljs/core';
|
|
2
|
+
import { RPC_CLIENT } from '../client/client-protocol';
|
|
3
|
+
import { RpcUtil } from '../utils/rpc-util';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A component of the frontend (or of a backend calling another one) that the backend calls over the
|
|
7
|
+
* WebSocket connection: `RpcConnection.client<T>(id)` on the server is a proxy of it. Needs
|
|
8
|
+
* `rpc.transport: websocket`.
|
|
9
|
+
*/
|
|
10
|
+
export const RpcClient = <ComponentDecorator>function (...idOrOption: any): ClassDecorator {
|
|
11
|
+
return target => {
|
|
12
|
+
const { ids } = applyComponentDecorator(parseComponentOption(target, idOrOption), target);
|
|
13
|
+
const id = ids[1] ?? ids[0];
|
|
14
|
+
const path = RpcUtil.toPath(id);
|
|
15
|
+
applyComponentDecorator({ id: RPC_CLIENT, onActivation: ({ container }) => ({ path, get: () => container.get(id) }) }, target);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { ComponentDecorator, applyComponentDecorator, ComponentOption, parseComponentOption
|
|
2
|
-
import { AOP_POINTCUT
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { RpcUtil, ConverterUtil } from '../utils';
|
|
1
|
+
import { ComponentDecorator, applyComponentDecorator, ComponentOption, parseComponentOption } from '@celljs/core';
|
|
2
|
+
import { AOP_POINTCUT } from '@celljs/web';
|
|
3
|
+
import { RpcUtil } from '../utils/rpc-util';
|
|
4
|
+
import { RPC_SERVICE } from './rpc-protocol';
|
|
6
5
|
|
|
7
6
|
export const RPC_TAG = 'Rpc';
|
|
8
7
|
|
|
8
|
+
/**
|
|
9
|
+
* An RPC service: a component (it takes the options of `@Component`) whose methods are called with
|
|
10
|
+
* JSON-RPC at `POST /<rpc.path>/<id>` and over the WebSocket connection (`<id>/<method>`).
|
|
11
|
+
*/
|
|
9
12
|
export const Rpc = <ComponentDecorator>function (...idOrOption: any): ClassDecorator {
|
|
10
13
|
return target => {
|
|
11
14
|
const option = parseRpcOption(target, idOrOption);
|
|
@@ -15,8 +18,7 @@ export const Rpc = <ComponentDecorator>function (...idOrOption: any): ClassDecor
|
|
|
15
18
|
|
|
16
19
|
export function parseRpcOption(target: any, idOrOption: any) {
|
|
17
20
|
const parsed = parseComponentOption(target, idOrOption);
|
|
18
|
-
|
|
19
|
-
if (idOrOption[0].proxy === undefined) {
|
|
21
|
+
if (idOrOption[0]?.proxy === undefined) {
|
|
20
22
|
parsed.proxy = true;
|
|
21
23
|
}
|
|
22
24
|
parsed.sysTags!.push(AOP_POINTCUT, RPC_TAG);
|
|
@@ -25,17 +27,7 @@ export function parseRpcOption(target: any, idOrOption: any) {
|
|
|
25
27
|
|
|
26
28
|
export function applyRpcDecorator(option: ComponentOption, target: any) {
|
|
27
29
|
const { ids } = applyComponentDecorator(option, target);
|
|
28
|
-
const id = ids[1]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const logger = context.container.get<Logger>(Logger);
|
|
33
|
-
const errorConverters = ConverterUtil.getGlobalErrorConverters(context.container as Container);
|
|
34
|
-
const errorConverter = ConverterUtil.getErrorConverters(id, context.container as Container);
|
|
35
|
-
if (errorConverter) {
|
|
36
|
-
errorConverters.push(errorConverter);
|
|
37
|
-
}
|
|
38
|
-
return new JsonRpcConnectionHandler(RpcUtil.toPath(id), () => t, errorConverters, pipeManager, logger);
|
|
39
|
-
}}, target);
|
|
40
|
-
}
|
|
41
|
-
|
|
30
|
+
const id = ids[1] ?? ids[0];
|
|
31
|
+
const path = RpcUtil.toPath(id);
|
|
32
|
+
return applyComponentDecorator({ id: RPC_SERVICE, onActivation: ({ container }) => ({ path, id, get: () => container.get(id) }) }, target);
|
|
33
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Autowired, Component, Optional } from '@celljs/core';
|
|
2
|
+
import { JsonRpc } from '../protocol';
|
|
3
|
+
import { RpcMethodUtil } from '../utils/rpc-method-util';
|
|
4
|
+
import { RPC_CLIENT, RpcClientMetadata } from './client-protocol';
|
|
5
|
+
|
|
6
|
+
export const RpcClientRegistry = Symbol('RpcClientRegistry');
|
|
7
|
+
|
|
8
|
+
/** The `@RpcClient` components, which answer the calls a backend makes over the WebSocket connection. */
|
|
9
|
+
export interface RpcClientRegistry {
|
|
10
|
+
readonly empty: boolean;
|
|
11
|
+
/** The response to a request of the server (`<client>/<method>`). */
|
|
12
|
+
handle(request: JsonRpc.Request): Promise<JsonRpc.Response>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Component(RpcClientRegistry)
|
|
16
|
+
export class RpcClientRegistryImpl implements RpcClientRegistry {
|
|
17
|
+
|
|
18
|
+
@Autowired(RPC_CLIENT) @Optional()
|
|
19
|
+
protected readonly clients: RpcClientMetadata[] = [];
|
|
20
|
+
|
|
21
|
+
get empty(): boolean {
|
|
22
|
+
return this.clients.length === 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async handle(request: JsonRpc.Request): Promise<JsonRpc.Response> {
|
|
26
|
+
const id = request.id ?? null;
|
|
27
|
+
const parts = RpcMethodUtil.split(request.method);
|
|
28
|
+
const metadata = parts && this.clients.find(c => c.path === parts[0]);
|
|
29
|
+
if (!parts || !metadata) {
|
|
30
|
+
return JsonRpc.error(id, JsonRpc.METHOD_NOT_FOUND, `No @RpcClient for ${request.method}.`);
|
|
31
|
+
}
|
|
32
|
+
const client = metadata.get() as Record<string, (...args: unknown[]) => unknown>;
|
|
33
|
+
if (!RpcMethodUtil.callable(client, parts[1])) {
|
|
34
|
+
return JsonRpc.error(id, JsonRpc.METHOD_NOT_FOUND, `${parts[0]} has no method ${parts[1]}.`);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return JsonRpc.result(id, await client[parts[1]](...(request.params ?? [])));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return JsonRpc.error(id, JsonRpc.SERVER_ERROR, error instanceof Error ? error.message : String(error));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/common/constants.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { JsonRpc } from '../protocol';
|
|
2
|
+
|
|
1
3
|
export const ErrorConverter = Symbol('ErrorConverter');
|
|
2
4
|
|
|
5
|
+
/** Named `GlobalConverter`, an `ErrorConverter` applies to every service; named after a service id, to that one. */
|
|
3
6
|
export const GlobalConverter = Symbol('GlobalConverter');
|
|
4
7
|
|
|
5
8
|
export interface ErrorConverter {
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
/** Server: the JSON-RPC error for an error a service threw, or undefined for the default. */
|
|
10
|
+
serialize(error: unknown): JsonRpc.ErrorObject | undefined;
|
|
11
|
+
/** Client: the error to throw for the error of a response, or undefined to keep it. */
|
|
12
|
+
deserialize(error: Error): Error | undefined;
|
|
8
13
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export const EndpointResolver = Symbol('EndpointResolver');
|
|
2
2
|
|
|
3
3
|
export interface EndpointResolver {
|
|
4
|
+
/** The HTTP URL of a service. */
|
|
4
5
|
resolve(serviceIdentifier: string): Promise<string>;
|
|
6
|
+
/** The URL of the WebSocket endpoint: `rpc.websocket.endpoint`, or `/<rpc.path>/ws` of the page's origin. */
|
|
7
|
+
resolveWebSocket?(): Promise<string>;
|
|
5
8
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Autowired, Component, Value } from '@celljs/core';
|
|
2
|
-
import { RPC_PATH } from '../constants';
|
|
2
|
+
import { RPC_PATH, RPC_WEBSOCKET_PATH } from '../constants';
|
|
3
3
|
import { PathResolver } from '@celljs/web';
|
|
4
4
|
import { EndpointNotFoundError } from '../error';
|
|
5
5
|
import { EndpointResolver } from './endpoint-protocol';
|
|
@@ -7,15 +7,18 @@ import { EndpointResolver } from './endpoint-protocol';
|
|
|
7
7
|
@Component(EndpointResolver)
|
|
8
8
|
export class EndpointResolverImpl implements EndpointResolver {
|
|
9
9
|
|
|
10
|
-
@Value('
|
|
10
|
+
@Value('rpc.endpoint')
|
|
11
11
|
protected readonly endpoint?: { [id: string]: string };
|
|
12
12
|
|
|
13
|
-
@Value('
|
|
13
|
+
@Value('rpc.defaultEndpoint')
|
|
14
14
|
protected readonly defaultEndpoint?: string;
|
|
15
15
|
|
|
16
16
|
@Value(RPC_PATH)
|
|
17
17
|
protected readonly rpcPath: string;
|
|
18
18
|
|
|
19
|
+
@Value('rpc.websocket.endpoint')
|
|
20
|
+
protected readonly websocketEndpoint?: string;
|
|
21
|
+
|
|
19
22
|
@Autowired(PathResolver)
|
|
20
23
|
protected pathResolver: PathResolver;
|
|
21
24
|
|
|
@@ -43,4 +46,15 @@ export class EndpointResolverImpl implements EndpointResolver {
|
|
|
43
46
|
.replace(/{serviceIdentifier}/g, serviceIdentifier);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
async resolveWebSocket(): Promise<string> {
|
|
50
|
+
if (this.websocketEndpoint) {
|
|
51
|
+
return this.websocketEndpoint.replace(/{rpcPath}/g, await this.pathResolver.resolve(this.rpcPath));
|
|
52
|
+
}
|
|
53
|
+
if (typeof location === 'undefined') {
|
|
54
|
+
throw new EndpointNotFoundError('rpc.websocket.endpoint');
|
|
55
|
+
}
|
|
56
|
+
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
57
|
+
return `${protocol}//${location.host}${await this.pathResolver.resolve(this.rpcPath, RPC_WEBSOCKET_PATH)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
@@ -1,7 +1,46 @@
|
|
|
1
|
-
import { CustomError } from '@celljs/core';
|
|
1
|
+
import { ApplicationError, CustomError } from '@celljs/core';
|
|
2
|
+
import { JsonRpc } from '../protocol';
|
|
2
3
|
|
|
3
4
|
export class EndpointNotFoundError extends CustomError {
|
|
4
5
|
constructor(public serviceId: string) {
|
|
5
|
-
super(`No endpoint found
|
|
6
|
+
super(`No endpoint found for the RPC service ${serviceId}: set rpc.endpoint.${serviceId} or rpc.defaultEndpoint.`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** What the remote side of a call answered with, or why there is no answer. */
|
|
11
|
+
export interface RpcErrorData {
|
|
12
|
+
/** HTTP status: of the error the service threw (`HttpError`), or of the answer of an HTTP call. */
|
|
13
|
+
status?: number;
|
|
14
|
+
/** `application` for an `ApplicationError`, whose code and data are kept. */
|
|
15
|
+
kind?: 'application';
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A call that failed: `code` is the JSON-RPC error code ({@link JsonRpc}), `data.status` the HTTP status
|
|
21
|
+
* when there is one. The stack ends with the place of the call.
|
|
22
|
+
*/
|
|
23
|
+
export class RpcError extends CustomError {
|
|
24
|
+
constructor(message: string, readonly code: number = JsonRpc.SERVER_ERROR, readonly data: RpcErrorData = {}) {
|
|
25
|
+
super(message);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get status(): number | undefined {
|
|
29
|
+
return this.data.status;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export namespace RpcErrorUtil {
|
|
34
|
+
|
|
35
|
+
/** The error of a JSON-RPC answer: an `ApplicationError` again when it was one, an {@link RpcError} otherwise. */
|
|
36
|
+
export function fromErrorObject(error: JsonRpc.ErrorObject, call: Error): Error {
|
|
37
|
+
const data = (typeof error.data === 'object' && error.data !== null ? error.data : {}) as RpcErrorData;
|
|
38
|
+
const stack = call.stack?.replace(/^.*\n/, '') ?? '';
|
|
39
|
+
if (data.kind === 'application') {
|
|
40
|
+
return ApplicationError.fromJson(error.code, { message: error.message, data: data.data, stack: `Error: ${error.message}\n${stack}` });
|
|
41
|
+
}
|
|
42
|
+
const result = new RpcError(error.message, error.code, data);
|
|
43
|
+
result.stack = `${result.name}: ${result.message}\n${stack}`;
|
|
44
|
+
return result;
|
|
6
45
|
}
|
|
7
46
|
}
|
package/src/common/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * from './annotation';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './client';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export * from './converter';
|
|
3
5
|
export * from './endpoint';
|
|
4
6
|
export * from './error';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
+
export * from './processor';
|
|
8
|
+
export * from './protocol';
|
|
7
9
|
export * from './proxy';
|
|
10
|
+
export * from './transport';
|
|
8
11
|
export * from './utils';
|
|
9
|
-
export * from './constants';
|
|
10
|
-
export * from './converter';
|
|
11
|
-
export * from './processor';
|
package/src/common/module.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { autoBind } from '@celljs/core';
|
|
2
|
-
import { ProxyProvider } from './proxy';
|
|
1
|
+
import { autoBind, ComponentId } from '@celljs/core';
|
|
3
2
|
import { ID_KEY, RPC } from './annotation';
|
|
4
|
-
import {
|
|
3
|
+
import { RpcProxy } from './proxy';
|
|
4
|
+
import { RpcTransportProvider } from './transport';
|
|
5
|
+
import { ConverterUtil, RpcUtil } from './utils';
|
|
5
6
|
import './index';
|
|
6
7
|
|
|
7
8
|
export default autoBind(bind => {
|
|
8
|
-
|
|
9
|
+
// @Autorpc(id) and RpcUtil.get(id): a proxy of the service, with its error converters.
|
|
9
10
|
bind(RPC).toDynamicValue(ctx => {
|
|
10
|
-
const id = ctx.target.tags![ID_KEY];
|
|
11
|
+
const id = ctx.target.tags![ID_KEY] as ComponentId;
|
|
11
12
|
const path = RpcUtil.toPath(id);
|
|
12
|
-
const proxyProvider = ctx.container.get<ProxyProvider>(ProxyProvider);
|
|
13
13
|
const errorConverters = ConverterUtil.getGlobalErrorConverters(ctx.container);
|
|
14
14
|
const errorConverter = ConverterUtil.getErrorConverters(id, ctx.container);
|
|
15
15
|
if (errorConverter) {
|
|
16
16
|
errorConverters.push(errorConverter);
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return RpcProxy.create(path, ctx.container.get<RpcTransportProvider>(RpcTransportProvider).provide(path), errorConverters);
|
|
19
19
|
});
|
|
20
|
-
|
|
21
20
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Component } from '@celljs/core';
|
|
2
2
|
import { ClientConfigProcessor } from './processor-protocol';
|
|
3
|
-
import {
|
|
3
|
+
import { RequestConfig } from '@celljs/http';
|
|
4
4
|
|
|
5
5
|
@Component(ClientConfigProcessor)
|
|
6
6
|
export class NoOpClientConfigProcessor implements ClientConfigProcessor {
|
|
7
7
|
|
|
8
|
-
async process(config:
|
|
8
|
+
async process(config: RequestConfig): Promise<void> {
|
|
9
9
|
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestConfig } from '@celljs/http';
|
|
2
2
|
|
|
3
3
|
export const ClientConfigProcessor = Symbol('ClientConfigProcessor');
|
|
4
4
|
|
|
5
5
|
export interface ClientConfigProcessor {
|
|
6
|
-
process(config:
|
|
6
|
+
process(config: RequestConfig): Promise<void>;
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './json-rpc';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 (https://www.jsonrpc.org/specification), the format of every RPC message: a POST body
|
|
3
|
+
* of `/<rpc.path>/<service>`, or a WebSocket message, where methods are `<service>/<method>`.
|
|
4
|
+
*/
|
|
5
|
+
export namespace JsonRpc {
|
|
6
|
+
|
|
7
|
+
export type Id = number | string;
|
|
8
|
+
|
|
9
|
+
export interface Request {
|
|
10
|
+
jsonrpc: '2.0';
|
|
11
|
+
/** Absent for a notification, which gets no response. */
|
|
12
|
+
id?: Id;
|
|
13
|
+
method: string;
|
|
14
|
+
params?: unknown[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ErrorObject {
|
|
18
|
+
code: number;
|
|
19
|
+
message: string;
|
|
20
|
+
data?: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface Response {
|
|
24
|
+
jsonrpc: '2.0';
|
|
25
|
+
id: Id | null;
|
|
26
|
+
result?: unknown;
|
|
27
|
+
error?: ErrorObject;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type Message = Request | Response;
|
|
31
|
+
|
|
32
|
+
export const PARSE_ERROR = -32700;
|
|
33
|
+
export const INVALID_REQUEST = -32600;
|
|
34
|
+
export const METHOD_NOT_FOUND = -32601;
|
|
35
|
+
export const INVALID_PARAMS = -32602;
|
|
36
|
+
export const INTERNAL_ERROR = -32603;
|
|
37
|
+
/** An error thrown by the service, or an HTTP error status (`data.status`). */
|
|
38
|
+
export const SERVER_ERROR = -32000;
|
|
39
|
+
/** The WebSocket connection closed before the response arrived. */
|
|
40
|
+
export const CONNECTION_CLOSED = -32003;
|
|
41
|
+
/** No response within the timeout. */
|
|
42
|
+
export const TIMEOUT = -32004;
|
|
43
|
+
|
|
44
|
+
export function isRequest(message: unknown): message is Request {
|
|
45
|
+
return isObject(message) && message.jsonrpc === '2.0' && typeof message.method === 'string'
|
|
46
|
+
&& (message.params === undefined || Array.isArray(message.params)) && (message.id === undefined || isId(message.id));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function isResponse(message: unknown): message is Response {
|
|
50
|
+
return isObject(message) && message.jsonrpc === '2.0' && typeof message.method !== 'string' && ('result' in message || isObject(message.error))
|
|
51
|
+
&& (message.id === null || isId(message.id));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function request(id: Id | undefined, method: string, params: unknown[]): Request {
|
|
55
|
+
return id === undefined ? { jsonrpc: '2.0', method, params } : { jsonrpc: '2.0', id, method, params };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function result(id: Id | null, value: unknown): Response {
|
|
59
|
+
// undefined is not JSON: a method without a result answers null.
|
|
60
|
+
return { jsonrpc: '2.0', id, result: value === undefined ? null : value };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function error(id: Id | null, code: number, message: string, data?: unknown): Response {
|
|
64
|
+
return { jsonrpc: '2.0', id, error: data === undefined ? { code, message } : { code, message, data } };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isId(id: unknown): id is Id {
|
|
68
|
+
return typeof id === 'string' || (typeof id === 'number' && Number.isFinite(id));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isObject(value: unknown): value is Record<string, any> {
|
|
72
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ErrorConverter } from '../converter';
|
|
2
|
+
import { RpcErrorUtil } from '../error';
|
|
3
|
+
import { RpcTransport } from '../transport/transport-protocol';
|
|
4
|
+
|
|
5
|
+
/** A typed proxy of a remote service: every method returns a promise of the remote result. */
|
|
6
|
+
export namespace RpcProxy {
|
|
7
|
+
|
|
8
|
+
export function create<T extends object>(service: string, transport: RpcTransport, errorConverters: ErrorConverter[] = []): T {
|
|
9
|
+
const methods = new Map<string, (...args: unknown[]) => Promise<unknown>>();
|
|
10
|
+
return new Proxy({} as T, {
|
|
11
|
+
get(_target, property) {
|
|
12
|
+
// Not a thenable, not serializable: awaiting or logging the proxy makes no call.
|
|
13
|
+
if (typeof property !== 'string' || property === 'then' || property === 'toJSON') {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
let method = methods.get(property);
|
|
17
|
+
if (!method) {
|
|
18
|
+
method = (...params: unknown[]) => invoke(service, property, params, transport, errorConverters);
|
|
19
|
+
methods.set(property, method);
|
|
20
|
+
}
|
|
21
|
+
return method;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function invoke(service: string, method: string, params: unknown[], transport: RpcTransport, errorConverters: ErrorConverter[]): Promise<unknown> {
|
|
27
|
+
// Created before the call, so the stack of the error leads to the caller.
|
|
28
|
+
const call = new Error(`${service}.${method}`);
|
|
29
|
+
const response = await transport.call(service, method, params);
|
|
30
|
+
if (!response.error) {
|
|
31
|
+
return response.result;
|
|
32
|
+
}
|
|
33
|
+
const error = RpcErrorUtil.fromErrorObject(response.error, call);
|
|
34
|
+
for (const converter of errorConverters) {
|
|
35
|
+
const converted = converter.deserialize(error);
|
|
36
|
+
if (converted) {
|
|
37
|
+
throw converted;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|