@celljs/rpc 4.2.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.
Files changed (545) hide show
  1. package/README.md +117 -1
  2. package/cell.schema.json +100 -0
  3. package/cell.yml +12 -8
  4. package/esm/common/annotation/index.d.ts +2 -0
  5. package/esm/common/annotation/index.js +2 -0
  6. package/esm/common/annotation/index.js.map +1 -1
  7. package/esm/common/annotation/rpc-client.d.ts +7 -0
  8. package/esm/common/annotation/rpc-client.js +18 -0
  9. package/esm/common/annotation/rpc-client.js.map +1 -0
  10. package/esm/common/annotation/rpc-protocol.d.ts +7 -0
  11. package/esm/common/annotation/rpc-protocol.js +2 -0
  12. package/esm/common/annotation/rpc-protocol.js.map +1 -0
  13. package/esm/common/annotation/rpc.d.ts +4 -0
  14. package/esm/common/annotation/rpc.js +14 -18
  15. package/esm/common/annotation/rpc.js.map +1 -1
  16. package/esm/common/client/client-protocol.d.ts +6 -0
  17. package/esm/common/client/client-protocol.js +2 -0
  18. package/esm/common/client/client-protocol.js.map +1 -0
  19. package/esm/common/client/index.d.ts +2 -0
  20. package/esm/common/client/index.js +3 -0
  21. package/esm/common/client/index.js.map +1 -0
  22. package/esm/common/client/rpc-client-registry.d.ts +14 -0
  23. package/esm/common/client/rpc-client-registry.js +51 -0
  24. package/esm/common/client/rpc-client-registry.js.map +1 -0
  25. package/esm/common/constants.d.ts +3 -1
  26. package/esm/common/constants.js +3 -1
  27. package/esm/common/constants.js.map +1 -1
  28. package/esm/common/converter/converter-protocol.d.ts +6 -2
  29. package/esm/common/converter/converter-protocol.js +1 -0
  30. package/esm/common/converter/converter-protocol.js.map +1 -1
  31. package/esm/common/endpoint/endpoint-protocol.d.ts +3 -0
  32. package/esm/common/endpoint/endpoint-resolver.d.ts +2 -0
  33. package/esm/common/endpoint/endpoint-resolver.js +17 -3
  34. package/esm/common/endpoint/endpoint-resolver.js.map +1 -1
  35. package/esm/common/error/error.d.ts +23 -0
  36. package/esm/common/error/error.js +34 -2
  37. package/esm/common/error/error.js.map +1 -1
  38. package/esm/common/index.d.ts +6 -6
  39. package/esm/common/index.js +6 -6
  40. package/esm/common/index.js.map +1 -1
  41. package/esm/common/module.js +5 -4
  42. package/esm/common/module.js.map +1 -1
  43. package/esm/common/processor/client-config-processor.d.ts +2 -2
  44. package/esm/common/processor/client-config-processor.js.map +1 -1
  45. package/esm/common/processor/processor-protocol.d.ts +2 -2
  46. package/esm/common/protocol/index.d.ts +1 -0
  47. package/esm/common/protocol/index.js +2 -0
  48. package/esm/common/protocol/index.js.map +1 -0
  49. package/esm/common/protocol/json-rpc.d.ts +42 -0
  50. package/esm/common/protocol/json-rpc.js +48 -0
  51. package/esm/common/protocol/json-rpc.js.map +1 -0
  52. package/esm/common/proxy/index.d.ts +1 -4
  53. package/esm/common/proxy/index.js +1 -4
  54. package/esm/common/proxy/index.js.map +1 -1
  55. package/esm/common/proxy/rpc-proxy.d.ts +6 -0
  56. package/esm/common/proxy/rpc-proxy.js +40 -0
  57. package/esm/common/proxy/rpc-proxy.js.map +1 -0
  58. package/esm/common/transport/http-transport.d.ts +50 -0
  59. package/esm/common/transport/http-transport.js +98 -0
  60. package/esm/common/transport/http-transport.js.map +1 -0
  61. package/esm/common/transport/index.d.ts +4 -0
  62. package/esm/common/transport/index.js +5 -0
  63. package/esm/common/transport/index.js.map +1 -0
  64. package/esm/common/transport/transport-protocol.d.ts +12 -0
  65. package/esm/common/transport/transport-protocol.js +2 -0
  66. package/esm/common/transport/transport-protocol.js.map +1 -0
  67. package/esm/common/transport/transport-provider.d.ts +34 -0
  68. package/esm/common/transport/transport-provider.js +103 -0
  69. package/esm/common/transport/transport-provider.js.map +1 -0
  70. package/esm/common/transport/websocket-transport.d.ts +54 -0
  71. package/esm/common/transport/websocket-transport.js +144 -0
  72. package/esm/common/transport/websocket-transport.js.map +1 -0
  73. package/esm/common/utils/index.d.ts +1 -1
  74. package/esm/common/utils/index.js +1 -1
  75. package/esm/common/utils/index.js.map +1 -1
  76. package/esm/common/utils/rpc-method-util.d.ts +10 -0
  77. package/esm/common/utils/rpc-method-util.js +28 -0
  78. package/esm/common/utils/rpc-method-util.js.map +1 -0
  79. package/esm/common/utils/rpc-util.d.ts +9 -9
  80. package/esm/common/utils/rpc-util.js +24 -30
  81. package/esm/common/utils/rpc-util.js.map +1 -1
  82. package/esm/node/connection/connection-protocol.d.ts +26 -0
  83. package/esm/node/connection/connection-protocol.js +3 -0
  84. package/esm/node/connection/connection-protocol.js.map +1 -0
  85. package/esm/node/connection/index.d.ts +4 -0
  86. package/esm/node/connection/index.js +5 -0
  87. package/esm/node/connection/index.js.map +1 -0
  88. package/esm/node/connection/rpc-connection-manager.d.ts +10 -0
  89. package/esm/node/connection/rpc-connection-manager.js +35 -0
  90. package/esm/node/connection/rpc-connection-manager.js.map +1 -0
  91. package/esm/node/connection/rpc-connection.d.ts +33 -0
  92. package/esm/node/connection/rpc-connection.js +106 -0
  93. package/esm/node/connection/rpc-connection.js.map +1 -0
  94. package/esm/node/connection/rpc-context.d.ts +14 -0
  95. package/esm/node/connection/rpc-context.js +29 -0
  96. package/esm/node/connection/rpc-context.js.map +1 -0
  97. package/esm/node/index.d.ts +3 -2
  98. package/esm/node/index.js +3 -2
  99. package/esm/node/index.js.map +1 -1
  100. package/esm/node/server/index.d.ts +2 -0
  101. package/esm/node/server/index.js +3 -0
  102. package/esm/node/server/index.js.map +1 -0
  103. package/esm/node/server/rpc-handler-adapter.d.ts +15 -0
  104. package/esm/node/server/rpc-handler-adapter.js +74 -0
  105. package/esm/node/server/rpc-handler-adapter.js.map +1 -0
  106. package/esm/node/server/rpc-invoker.d.ts +28 -0
  107. package/esm/node/server/rpc-invoker.js +113 -0
  108. package/esm/node/server/rpc-invoker.js.map +1 -0
  109. package/esm/node/test/websocket-fixture-protocol.d.ts +36 -0
  110. package/esm/node/test/websocket-fixture-protocol.js +7 -0
  111. package/esm/node/test/websocket-fixture-protocol.js.map +1 -0
  112. package/esm/node/test/websocket-fixture.d.ts +40 -0
  113. package/esm/node/test/websocket-fixture.js +128 -0
  114. package/esm/node/test/websocket-fixture.js.map +1 -0
  115. package/esm/node/websocket/index.d.ts +4 -0
  116. package/esm/node/websocket/index.js +5 -0
  117. package/esm/node/websocket/index.js.map +1 -0
  118. package/esm/node/websocket/rpc-websocket-server.d.ts +45 -0
  119. package/esm/node/websocket/rpc-websocket-server.js +167 -0
  120. package/esm/node/websocket/rpc-websocket-server.js.map +1 -0
  121. package/esm/node/websocket/websocket-connection.d.ts +55 -0
  122. package/esm/node/websocket/websocket-connection.js +181 -0
  123. package/esm/node/websocket/websocket-connection.js.map +1 -0
  124. package/esm/node/websocket/websocket-exchange.d.ts +38 -0
  125. package/esm/node/websocket/websocket-exchange.js +124 -0
  126. package/esm/node/websocket/websocket-exchange.js.map +1 -0
  127. package/esm/node/websocket/websocket-frames.d.ts +31 -0
  128. package/esm/node/websocket/websocket-frames.js +119 -0
  129. package/esm/node/websocket/websocket-frames.js.map +1 -0
  130. package/lib/common/annotation/index.d.ts +2 -0
  131. package/lib/common/annotation/index.d.ts.map +1 -1
  132. package/lib/common/annotation/index.js +2 -0
  133. package/lib/common/annotation/index.js.map +1 -1
  134. package/lib/common/annotation/rpc-client.d.ts +8 -0
  135. package/lib/common/annotation/rpc-client.d.ts.map +1 -0
  136. package/lib/common/annotation/rpc-client.js +21 -0
  137. package/lib/common/annotation/rpc-client.js.map +1 -0
  138. package/lib/common/annotation/rpc-protocol.d.ts +8 -0
  139. package/lib/common/annotation/rpc-protocol.d.ts.map +1 -0
  140. package/lib/common/annotation/rpc-protocol.js +5 -0
  141. package/lib/common/annotation/rpc-protocol.js.map +1 -0
  142. package/lib/common/annotation/rpc.d.ts +4 -0
  143. package/lib/common/annotation/rpc.d.ts.map +1 -1
  144. package/lib/common/annotation/rpc.js +12 -16
  145. package/lib/common/annotation/rpc.js.map +1 -1
  146. package/lib/common/client/client-protocol.d.ts +7 -0
  147. package/lib/common/client/client-protocol.d.ts.map +1 -0
  148. package/lib/common/client/client-protocol.js +5 -0
  149. package/lib/common/client/client-protocol.js.map +1 -0
  150. package/lib/common/client/index.d.ts +3 -0
  151. package/lib/common/client/index.d.ts.map +1 -0
  152. package/lib/common/{handler → client}/index.js +2 -2
  153. package/lib/common/client/index.js.map +1 -0
  154. package/lib/common/client/rpc-client-registry.d.ts +15 -0
  155. package/lib/common/client/rpc-client-registry.d.ts.map +1 -0
  156. package/lib/common/client/rpc-client-registry.js +54 -0
  157. package/lib/common/client/rpc-client-registry.js.map +1 -0
  158. package/lib/common/constants.d.ts +3 -1
  159. package/lib/common/constants.d.ts.map +1 -1
  160. package/lib/common/constants.js +4 -2
  161. package/lib/common/constants.js.map +1 -1
  162. package/lib/common/converter/converter-protocol.d.ts +6 -2
  163. package/lib/common/converter/converter-protocol.d.ts.map +1 -1
  164. package/lib/common/converter/converter-protocol.js +1 -0
  165. package/lib/common/converter/converter-protocol.js.map +1 -1
  166. package/lib/common/endpoint/endpoint-protocol.d.ts +3 -0
  167. package/lib/common/endpoint/endpoint-protocol.d.ts.map +1 -1
  168. package/lib/common/endpoint/endpoint-resolver.d.ts +2 -0
  169. package/lib/common/endpoint/endpoint-resolver.d.ts.map +1 -1
  170. package/lib/common/endpoint/endpoint-resolver.js +16 -2
  171. package/lib/common/endpoint/endpoint-resolver.js.map +1 -1
  172. package/lib/common/error/error.d.ts +23 -0
  173. package/lib/common/error/error.d.ts.map +1 -1
  174. package/lib/common/error/error.js +35 -2
  175. package/lib/common/error/error.js.map +1 -1
  176. package/lib/common/index.d.ts +6 -6
  177. package/lib/common/index.d.ts.map +1 -1
  178. package/lib/common/index.js +6 -6
  179. package/lib/common/index.js.map +1 -1
  180. package/lib/common/module.d.ts.map +1 -1
  181. package/lib/common/module.js +4 -3
  182. package/lib/common/module.js.map +1 -1
  183. package/lib/common/processor/client-config-processor.d.ts +2 -2
  184. package/lib/common/processor/client-config-processor.d.ts.map +1 -1
  185. package/lib/common/processor/client-config-processor.js.map +1 -1
  186. package/lib/common/processor/processor-protocol.d.ts +2 -2
  187. package/lib/common/processor/processor-protocol.d.ts.map +1 -1
  188. package/lib/common/protocol/index.d.ts +2 -0
  189. package/lib/common/protocol/index.d.ts.map +1 -0
  190. package/lib/common/{channal → protocol}/index.js +1 -2
  191. package/lib/common/protocol/index.js.map +1 -0
  192. package/lib/common/protocol/json-rpc.d.ts +43 -0
  193. package/lib/common/protocol/json-rpc.d.ts.map +1 -0
  194. package/lib/common/protocol/json-rpc.js +51 -0
  195. package/lib/common/protocol/json-rpc.js.map +1 -0
  196. package/lib/common/proxy/index.d.ts +1 -4
  197. package/lib/common/proxy/index.d.ts.map +1 -1
  198. package/lib/common/proxy/index.js +1 -4
  199. package/lib/common/proxy/index.js.map +1 -1
  200. package/lib/common/proxy/rpc-proxy.d.ts +7 -0
  201. package/lib/common/proxy/rpc-proxy.d.ts.map +1 -0
  202. package/lib/common/proxy/rpc-proxy.js +43 -0
  203. package/lib/common/proxy/rpc-proxy.js.map +1 -0
  204. package/lib/common/transport/http-transport.d.ts +51 -0
  205. package/lib/common/transport/http-transport.d.ts.map +1 -0
  206. package/lib/common/transport/http-transport.js +102 -0
  207. package/lib/common/transport/http-transport.js.map +1 -0
  208. package/lib/common/transport/index.d.ts +5 -0
  209. package/lib/common/transport/index.d.ts.map +1 -0
  210. package/lib/common/{factory → transport}/index.js +4 -4
  211. package/lib/common/transport/index.js.map +1 -0
  212. package/lib/common/transport/transport-protocol.d.ts +13 -0
  213. package/lib/common/transport/transport-protocol.d.ts.map +1 -0
  214. package/lib/common/transport/transport-protocol.js +5 -0
  215. package/lib/common/transport/transport-protocol.js.map +1 -0
  216. package/lib/common/transport/transport-provider.d.ts +35 -0
  217. package/lib/common/transport/transport-provider.d.ts.map +1 -0
  218. package/lib/common/transport/transport-provider.js +106 -0
  219. package/lib/common/transport/transport-provider.js.map +1 -0
  220. package/lib/common/transport/websocket-transport.d.ts +55 -0
  221. package/lib/common/transport/websocket-transport.d.ts.map +1 -0
  222. package/lib/common/transport/websocket-transport.js +148 -0
  223. package/lib/common/transport/websocket-transport.js.map +1 -0
  224. package/lib/common/utils/index.d.ts +1 -1
  225. package/lib/common/utils/index.d.ts.map +1 -1
  226. package/lib/common/utils/index.js +1 -1
  227. package/lib/common/utils/index.js.map +1 -1
  228. package/lib/common/utils/rpc-method-util.d.ts +11 -0
  229. package/lib/common/utils/rpc-method-util.d.ts.map +1 -0
  230. package/lib/common/utils/rpc-method-util.js +31 -0
  231. package/lib/common/utils/rpc-method-util.js.map +1 -0
  232. package/lib/common/utils/rpc-util.d.ts +9 -9
  233. package/lib/common/utils/rpc-util.d.ts.map +1 -1
  234. package/lib/common/utils/rpc-util.js +24 -30
  235. package/lib/common/utils/rpc-util.js.map +1 -1
  236. package/lib/node/connection/connection-protocol.d.ts +27 -0
  237. package/lib/node/connection/connection-protocol.d.ts.map +1 -0
  238. package/lib/node/connection/connection-protocol.js +6 -0
  239. package/lib/node/connection/connection-protocol.js.map +1 -0
  240. package/lib/node/connection/index.d.ts +5 -0
  241. package/lib/node/connection/index.d.ts.map +1 -0
  242. package/lib/node/{channel → connection}/index.js +4 -4
  243. package/lib/node/connection/index.js.map +1 -0
  244. package/lib/node/connection/rpc-connection-manager.d.ts +11 -0
  245. package/lib/node/connection/rpc-connection-manager.d.ts.map +1 -0
  246. package/lib/node/connection/rpc-connection-manager.js +38 -0
  247. package/lib/node/connection/rpc-connection-manager.js.map +1 -0
  248. package/lib/node/connection/rpc-connection.d.ts +34 -0
  249. package/lib/node/connection/rpc-connection.d.ts.map +1 -0
  250. package/lib/node/connection/rpc-connection.js +110 -0
  251. package/lib/node/connection/rpc-connection.js.map +1 -0
  252. package/lib/node/connection/rpc-context.d.ts +15 -0
  253. package/lib/node/connection/rpc-context.d.ts.map +1 -0
  254. package/lib/node/connection/rpc-context.js +33 -0
  255. package/lib/node/connection/rpc-context.js.map +1 -0
  256. package/lib/node/index.d.ts +3 -2
  257. package/lib/node/index.d.ts.map +1 -1
  258. package/lib/node/index.js +3 -2
  259. package/lib/node/index.js.map +1 -1
  260. package/lib/node/rpc-http.spec.d.ts +2 -0
  261. package/lib/node/rpc-http.spec.d.ts.map +1 -0
  262. package/lib/node/rpc-http.spec.js +121 -0
  263. package/lib/node/rpc-http.spec.js.map +1 -0
  264. package/lib/node/rpc-websocket.spec.d.ts +6 -0
  265. package/lib/node/rpc-websocket.spec.d.ts.map +1 -0
  266. package/lib/node/rpc-websocket.spec.js +196 -0
  267. package/lib/node/rpc-websocket.spec.js.map +1 -0
  268. package/lib/node/server/index.d.ts +3 -0
  269. package/lib/node/server/index.d.ts.map +1 -0
  270. package/lib/node/{handler → server}/index.js +2 -2
  271. package/lib/node/server/index.js.map +1 -0
  272. package/lib/node/server/rpc-handler-adapter.d.ts +16 -0
  273. package/lib/node/server/rpc-handler-adapter.d.ts.map +1 -0
  274. package/lib/node/{handler/handler-adapter.js → server/rpc-handler-adapter.js} +40 -18
  275. package/lib/node/server/rpc-handler-adapter.js.map +1 -0
  276. package/lib/node/server/rpc-invoker.d.ts +29 -0
  277. package/lib/node/server/rpc-invoker.d.ts.map +1 -0
  278. package/lib/node/server/rpc-invoker.js +116 -0
  279. package/lib/node/server/rpc-invoker.js.map +1 -0
  280. package/lib/node/test/websocket-fixture-protocol.d.ts +37 -0
  281. package/lib/node/test/websocket-fixture-protocol.d.ts.map +1 -0
  282. package/lib/node/test/websocket-fixture-protocol.js +10 -0
  283. package/lib/node/test/websocket-fixture-protocol.js.map +1 -0
  284. package/lib/node/test/websocket-fixture.d.ts +41 -0
  285. package/lib/node/test/websocket-fixture.d.ts.map +1 -0
  286. package/lib/node/test/websocket-fixture.js +135 -0
  287. package/lib/node/test/websocket-fixture.js.map +1 -0
  288. package/lib/node/websocket/index.d.ts +5 -0
  289. package/lib/node/websocket/index.d.ts.map +1 -0
  290. package/lib/node/websocket/index.js +21 -0
  291. package/lib/node/websocket/index.js.map +1 -0
  292. package/lib/node/websocket/rpc-websocket-server.d.ts +46 -0
  293. package/lib/node/websocket/rpc-websocket-server.d.ts.map +1 -0
  294. package/lib/node/websocket/rpc-websocket-server.js +170 -0
  295. package/lib/node/websocket/rpc-websocket-server.js.map +1 -0
  296. package/lib/node/websocket/websocket-connection.d.ts +56 -0
  297. package/lib/node/websocket/websocket-connection.d.ts.map +1 -0
  298. package/lib/node/websocket/websocket-connection.js +185 -0
  299. package/lib/node/websocket/websocket-connection.js.map +1 -0
  300. package/lib/node/websocket/websocket-exchange.d.ts +39 -0
  301. package/lib/node/websocket/websocket-exchange.d.ts.map +1 -0
  302. package/lib/node/websocket/websocket-exchange.js +128 -0
  303. package/lib/node/websocket/websocket-exchange.js.map +1 -0
  304. package/lib/node/websocket/websocket-frames.d.ts +32 -0
  305. package/lib/node/websocket/websocket-frames.d.ts.map +1 -0
  306. package/lib/node/websocket/websocket-frames.js +124 -0
  307. package/lib/node/websocket/websocket-frames.js.map +1 -0
  308. package/lib/node/websocket/websocket-frames.spec.d.ts +2 -0
  309. package/lib/node/websocket/websocket-frames.spec.d.ts.map +1 -0
  310. package/lib/node/websocket/websocket-frames.spec.js +59 -0
  311. package/lib/node/websocket/websocket-frames.spec.js.map +1 -0
  312. package/package.json +28 -25
  313. package/src/common/annotation/index.ts +2 -0
  314. package/src/common/annotation/rpc-client.ts +17 -0
  315. package/src/common/annotation/rpc-protocol.ts +8 -0
  316. package/src/common/annotation/rpc.ts +13 -21
  317. package/src/common/client/client-protocol.ts +7 -0
  318. package/src/common/client/index.ts +2 -0
  319. package/src/common/client/rpc-client-registry.ts +42 -0
  320. package/src/common/constants.ts +4 -1
  321. package/src/common/converter/converter-protocol.ts +7 -2
  322. package/src/common/endpoint/endpoint-protocol.ts +3 -0
  323. package/src/common/endpoint/endpoint-resolver.ts +18 -4
  324. package/src/common/error/error.ts +41 -2
  325. package/src/common/index.ts +6 -6
  326. package/src/common/module.ts +7 -8
  327. package/src/common/processor/client-config-processor.ts +2 -2
  328. package/src/common/processor/processor-protocol.ts +2 -2
  329. package/src/common/protocol/index.ts +1 -0
  330. package/src/common/protocol/json-rpc.ts +74 -0
  331. package/src/common/proxy/index.ts +1 -5
  332. package/src/common/proxy/rpc-proxy.ts +42 -0
  333. package/src/common/transport/http-transport.ts +134 -0
  334. package/src/common/transport/index.ts +4 -0
  335. package/src/common/transport/transport-protocol.ts +16 -0
  336. package/src/common/transport/transport-provider.ts +86 -0
  337. package/src/common/transport/websocket-transport.ts +171 -0
  338. package/src/common/utils/index.ts +1 -1
  339. package/src/common/utils/rpc-method-util.ts +26 -0
  340. package/src/common/utils/rpc-util.ts +24 -35
  341. package/src/node/connection/connection-protocol.ts +30 -0
  342. package/src/node/connection/index.ts +3 -0
  343. package/src/node/connection/rpc-connection-manager.ts +29 -0
  344. package/src/node/connection/rpc-connection.ts +122 -0
  345. package/src/node/connection/rpc-context.ts +29 -0
  346. package/src/node/index.ts +3 -2
  347. package/src/node/rpc-http.spec.ts +126 -0
  348. package/src/node/rpc-websocket.spec.ts +196 -0
  349. package/src/node/server/index.ts +2 -0
  350. package/src/node/server/rpc-handler-adapter.ts +60 -0
  351. package/src/node/server/rpc-invoker.ts +104 -0
  352. package/src/node/test/websocket-fixture-protocol.ts +32 -0
  353. package/src/node/test/websocket-fixture.ts +122 -0
  354. package/src/node/websocket/index.ts +4 -0
  355. package/src/node/websocket/rpc-websocket-server.ts +163 -0
  356. package/src/node/websocket/websocket-connection.ts +198 -0
  357. package/src/node/websocket/websocket-exchange.ts +138 -0
  358. package/src/node/websocket/websocket-frames.spec.ts +62 -0
  359. package/src/node/websocket/websocket-frames.ts +122 -0
  360. package/esm/common/channal/channel-protocol.d.ts +0 -51
  361. package/esm/common/channal/channel-protocol.js +0 -34
  362. package/esm/common/channal/channel-protocol.js.map +0 -1
  363. package/esm/common/channal/http-channel.d.ts +0 -8
  364. package/esm/common/channal/http-channel.js +0 -22
  365. package/esm/common/channal/http-channel.js.map +0 -1
  366. package/esm/common/channal/index.d.ts +0 -2
  367. package/esm/common/channal/index.js +0 -3
  368. package/esm/common/channal/index.js.map +0 -1
  369. package/esm/common/factory/connection-factory.d.ts +0 -9
  370. package/esm/common/factory/connection-factory.js +0 -25
  371. package/esm/common/factory/connection-factory.js.map +0 -1
  372. package/esm/common/factory/index.d.ts +0 -4
  373. package/esm/common/factory/index.js +0 -5
  374. package/esm/common/factory/index.js.map +0 -1
  375. package/esm/common/factory/proxy-factory.d.ts +0 -56
  376. package/esm/common/factory/proxy-factory.js +0 -177
  377. package/esm/common/factory/proxy-factory.js.map +0 -1
  378. package/esm/common/factory/reader.d.ts +0 -15
  379. package/esm/common/factory/reader.js +0 -44
  380. package/esm/common/factory/reader.js.map +0 -1
  381. package/esm/common/factory/writer.d.ts +0 -9
  382. package/esm/common/factory/writer.js +0 -21
  383. package/esm/common/factory/writer.js.map +0 -1
  384. package/esm/common/handler/connection-handler.d.ts +0 -6
  385. package/esm/common/handler/connection-handler.js +0 -4
  386. package/esm/common/handler/connection-handler.js.map +0 -1
  387. package/esm/common/handler/handler-protocol.d.ts +0 -6
  388. package/esm/common/handler/handler-protocol.js +0 -2
  389. package/esm/common/handler/handler-protocol.js.map +0 -1
  390. package/esm/common/handler/index.d.ts +0 -2
  391. package/esm/common/handler/index.js +0 -3
  392. package/esm/common/handler/index.js.map +0 -1
  393. package/esm/common/proxy/delegating-http-proxy-creator.d.ts +0 -23
  394. package/esm/common/proxy/delegating-http-proxy-creator.js +0 -86
  395. package/esm/common/proxy/delegating-http-proxy-creator.js.map +0 -1
  396. package/esm/common/proxy/http-proxy-creator.d.ts +0 -42
  397. package/esm/common/proxy/http-proxy-creator.js +0 -139
  398. package/esm/common/proxy/http-proxy-creator.js.map +0 -1
  399. package/esm/common/proxy/proxy-protocol.d.ts +0 -20
  400. package/esm/common/proxy/proxy-protocol.js +0 -3
  401. package/esm/common/proxy/proxy-protocol.js.map +0 -1
  402. package/esm/common/proxy/proxy-provider.d.ts +0 -9
  403. package/esm/common/proxy/proxy-provider.js +0 -40
  404. package/esm/common/proxy/proxy-provider.js.map +0 -1
  405. package/esm/common/utils/logger.d.ts +0 -8
  406. package/esm/common/utils/logger.js +0 -18
  407. package/esm/common/utils/logger.js.map +0 -1
  408. package/esm/node/channel/channel-manager.d.ts +0 -9
  409. package/esm/node/channel/channel-manager.js +0 -56
  410. package/esm/node/channel/channel-manager.js.map +0 -1
  411. package/esm/node/channel/channel-middleware.d.ts +0 -7
  412. package/esm/node/channel/channel-middleware.js +0 -37
  413. package/esm/node/channel/channel-middleware.js.map +0 -1
  414. package/esm/node/channel/channel-protocol.d.ts +0 -12
  415. package/esm/node/channel/channel-protocol.js +0 -6
  416. package/esm/node/channel/channel-protocol.js.map +0 -1
  417. package/esm/node/channel/channel-strategy.d.ts +0 -9
  418. package/esm/node/channel/channel-strategy.js +0 -61
  419. package/esm/node/channel/channel-strategy.js.map +0 -1
  420. package/esm/node/channel/index.d.ts +0 -4
  421. package/esm/node/channel/index.js +0 -5
  422. package/esm/node/channel/index.js.map +0 -1
  423. package/esm/node/handler/handler-adapter.d.ts +0 -13
  424. package/esm/node/handler/handler-adapter.js +0 -52
  425. package/esm/node/handler/handler-adapter.js.map +0 -1
  426. package/esm/node/handler/handler-protocol.d.ts +0 -1
  427. package/esm/node/handler/handler-protocol.js +0 -2
  428. package/esm/node/handler/handler-protocol.js.map +0 -1
  429. package/esm/node/handler/index.d.ts +0 -2
  430. package/esm/node/handler/index.js +0 -3
  431. package/esm/node/handler/index.js.map +0 -1
  432. package/lib/common/channal/channel-protocol.d.ts +0 -52
  433. package/lib/common/channal/channel-protocol.d.ts.map +0 -1
  434. package/lib/common/channal/channel-protocol.js +0 -38
  435. package/lib/common/channal/channel-protocol.js.map +0 -1
  436. package/lib/common/channal/http-channel.d.ts +0 -9
  437. package/lib/common/channal/http-channel.d.ts.map +0 -1
  438. package/lib/common/channal/http-channel.js +0 -26
  439. package/lib/common/channal/http-channel.js.map +0 -1
  440. package/lib/common/channal/index.d.ts +0 -3
  441. package/lib/common/channal/index.d.ts.map +0 -1
  442. package/lib/common/channal/index.js.map +0 -1
  443. package/lib/common/factory/connection-factory.d.ts +0 -10
  444. package/lib/common/factory/connection-factory.d.ts.map +0 -1
  445. package/lib/common/factory/connection-factory.js +0 -28
  446. package/lib/common/factory/connection-factory.js.map +0 -1
  447. package/lib/common/factory/index.d.ts +0 -5
  448. package/lib/common/factory/index.d.ts.map +0 -1
  449. package/lib/common/factory/index.js.map +0 -1
  450. package/lib/common/factory/proxy-factory.d.ts +0 -57
  451. package/lib/common/factory/proxy-factory.d.ts.map +0 -1
  452. package/lib/common/factory/proxy-factory.js +0 -182
  453. package/lib/common/factory/proxy-factory.js.map +0 -1
  454. package/lib/common/factory/reader.d.ts +0 -16
  455. package/lib/common/factory/reader.d.ts.map +0 -1
  456. package/lib/common/factory/reader.js +0 -48
  457. package/lib/common/factory/reader.js.map +0 -1
  458. package/lib/common/factory/writer.d.ts +0 -10
  459. package/lib/common/factory/writer.d.ts.map +0 -1
  460. package/lib/common/factory/writer.js +0 -25
  461. package/lib/common/factory/writer.js.map +0 -1
  462. package/lib/common/handler/connection-handler.d.ts +0 -7
  463. package/lib/common/handler/connection-handler.d.ts.map +0 -1
  464. package/lib/common/handler/connection-handler.js +0 -8
  465. package/lib/common/handler/connection-handler.js.map +0 -1
  466. package/lib/common/handler/handler-protocol.d.ts +0 -7
  467. package/lib/common/handler/handler-protocol.d.ts.map +0 -1
  468. package/lib/common/handler/handler-protocol.js +0 -5
  469. package/lib/common/handler/handler-protocol.js.map +0 -1
  470. package/lib/common/handler/index.d.ts +0 -3
  471. package/lib/common/handler/index.d.ts.map +0 -1
  472. package/lib/common/handler/index.js.map +0 -1
  473. package/lib/common/proxy/delegating-http-proxy-creator.d.ts +0 -24
  474. package/lib/common/proxy/delegating-http-proxy-creator.d.ts.map +0 -1
  475. package/lib/common/proxy/delegating-http-proxy-creator.js +0 -89
  476. package/lib/common/proxy/delegating-http-proxy-creator.js.map +0 -1
  477. package/lib/common/proxy/http-proxy-creator.d.ts +0 -43
  478. package/lib/common/proxy/http-proxy-creator.d.ts.map +0 -1
  479. package/lib/common/proxy/http-proxy-creator.js +0 -143
  480. package/lib/common/proxy/http-proxy-creator.js.map +0 -1
  481. package/lib/common/proxy/proxy-protocol.d.ts +0 -21
  482. package/lib/common/proxy/proxy-protocol.d.ts.map +0 -1
  483. package/lib/common/proxy/proxy-protocol.js +0 -6
  484. package/lib/common/proxy/proxy-protocol.js.map +0 -1
  485. package/lib/common/proxy/proxy-provider.d.ts +0 -10
  486. package/lib/common/proxy/proxy-provider.d.ts.map +0 -1
  487. package/lib/common/proxy/proxy-provider.js +0 -43
  488. package/lib/common/proxy/proxy-provider.js.map +0 -1
  489. package/lib/common/utils/logger.d.ts +0 -9
  490. package/lib/common/utils/logger.d.ts.map +0 -1
  491. package/lib/common/utils/logger.js +0 -22
  492. package/lib/common/utils/logger.js.map +0 -1
  493. package/lib/node/channel/channel-manager.d.ts +0 -10
  494. package/lib/node/channel/channel-manager.d.ts.map +0 -1
  495. package/lib/node/channel/channel-manager.js +0 -59
  496. package/lib/node/channel/channel-manager.js.map +0 -1
  497. package/lib/node/channel/channel-middleware.d.ts +0 -8
  498. package/lib/node/channel/channel-middleware.d.ts.map +0 -1
  499. package/lib/node/channel/channel-middleware.js +0 -40
  500. package/lib/node/channel/channel-middleware.js.map +0 -1
  501. package/lib/node/channel/channel-protocol.d.ts +0 -13
  502. package/lib/node/channel/channel-protocol.d.ts.map +0 -1
  503. package/lib/node/channel/channel-protocol.js +0 -9
  504. package/lib/node/channel/channel-protocol.js.map +0 -1
  505. package/lib/node/channel/channel-strategy.d.ts +0 -10
  506. package/lib/node/channel/channel-strategy.d.ts.map +0 -1
  507. package/lib/node/channel/channel-strategy.js +0 -64
  508. package/lib/node/channel/channel-strategy.js.map +0 -1
  509. package/lib/node/channel/index.d.ts +0 -5
  510. package/lib/node/channel/index.d.ts.map +0 -1
  511. package/lib/node/channel/index.js.map +0 -1
  512. package/lib/node/handler/handler-adapter.d.ts +0 -14
  513. package/lib/node/handler/handler-adapter.d.ts.map +0 -1
  514. package/lib/node/handler/handler-adapter.js.map +0 -1
  515. package/lib/node/handler/handler-protocol.d.ts +0 -2
  516. package/lib/node/handler/handler-protocol.d.ts.map +0 -1
  517. package/lib/node/handler/handler-protocol.js +0 -5
  518. package/lib/node/handler/handler-protocol.js.map +0 -1
  519. package/lib/node/handler/index.d.ts +0 -3
  520. package/lib/node/handler/index.d.ts.map +0 -1
  521. package/lib/node/handler/index.js.map +0 -1
  522. package/src/common/channal/channel-protocol.ts +0 -82
  523. package/src/common/channal/http-channel.ts +0 -30
  524. package/src/common/channal/index.ts +0 -2
  525. package/src/common/factory/connection-factory.ts +0 -21
  526. package/src/common/factory/index.ts +0 -4
  527. package/src/common/factory/proxy-factory.ts +0 -219
  528. package/src/common/factory/reader.ts +0 -50
  529. package/src/common/factory/writer.ts +0 -26
  530. package/src/common/handler/connection-handler.ts +0 -7
  531. package/src/common/handler/handler-protocol.ts +0 -8
  532. package/src/common/handler/index.ts +0 -2
  533. package/src/common/proxy/delegating-http-proxy-creator.ts +0 -68
  534. package/src/common/proxy/http-proxy-creator.ts +0 -179
  535. package/src/common/proxy/proxy-protocol.ts +0 -26
  536. package/src/common/proxy/proxy-provider.ts +0 -29
  537. package/src/common/utils/logger.ts +0 -23
  538. package/src/node/channel/channel-manager.ts +0 -44
  539. package/src/node/channel/channel-middleware.ts +0 -27
  540. package/src/node/channel/channel-protocol.ts +0 -21
  541. package/src/node/channel/channel-strategy.ts +0 -56
  542. package/src/node/channel/index.ts +0 -4
  543. package/src/node/handler/handler-adapter.ts +0 -38
  544. package/src/node/handler/handler-protocol.ts +0 -1
  545. package/src/node/handler/index.ts +0 -2
package/README.md CHANGED
@@ -1 +1,117 @@
1
- # Cell - Rpc Component
1
+ # Cell - Rpc Component
2
+
3
+ Typed remote calls between the frontend and the backend of a Cell application, or between Cell backends: [JSON-RPC 2.0](https://www.jsonrpc.org/specification) over HTTP or over one WebSocket connection, with the same TypeScript interface on both sides. Over WebSocket the backend can also call the frontend. Guide: [Frontend and RPC](https://cell.cellbang.com/guide/frontend).
4
+
5
+ ```bash
6
+ npm install @celljs/rpc
7
+ ```
8
+
9
+ ```ts
10
+ // src/common/greeting-protocol.ts
11
+ export const GreetingServer = Symbol('GreetingServer');
12
+ export interface GreetingServer {
13
+ greet(name: string): Promise<string>;
14
+ }
15
+
16
+ // src/node/greeting-server.ts
17
+ import { Rpc } from '@celljs/rpc';
18
+
19
+ @Rpc(GreetingServer)
20
+ export class GreetingServerImpl implements GreetingServer {
21
+ async greet(name: string) { return `Hello, ${name}`; }
22
+ }
23
+
24
+ // frontend
25
+ import { RpcUtil } from '@celljs/rpc';
26
+ const text = await RpcUtil.get<GreetingServer>(GreetingServer).greet('web');
27
+ ```
28
+
29
+ ## Services
30
+
31
+ `@Rpc(id)` registers the class as a component (it takes `ComponentOption`s like `@Component`) and serves it at `POST /<rpc.path>/<id>`, by default `/api/GreetingServer` (`rpc.path: api`, under `server.path`). The body is a JSON-RPC request (`{ "jsonrpc": "2.0", "id": 1, "method": "greet", "params": ["web"] }`), a batch (an array), or a notification (no `id`, answered with 204). Only methods declared by the class (and its superclasses) can be called, not `constructor` or those of `Object`. Parameters typed with a class are converted and validated by `@celljs/validation` when it is installed.
32
+
33
+ Errors answer as HTTP errors do: an `ApplicationError` keeps its code, message and data; a 4xx `HttpError` its message; any other error only `Internal Server Error` in production (`web.errors.exposeMessages`), and it is logged. Stacks never leave the server. The caller gets an `RpcError` with `code` (JSON-RPC), `status` (HTTP) and a stack that leads to the call, or the `ApplicationError` again.
34
+
35
+ ## Clients
36
+
37
+ | Where | How |
38
+ | --- | --- |
39
+ | Frontend of the same application | `RpcUtil.get<T>(Id)`: the endpoint is the page's origin |
40
+ | A component (frontend or backend) | `@Autorpc(Id) protected readonly service: T` |
41
+ | Anywhere, with an explicit URL, over HTTP | `RpcUtil.create<T>('https://host/api', Id)` |
42
+
43
+ The endpoint of a service is resolved from:
44
+
45
+ ```yaml
46
+ rpc:
47
+ endpoint: # per service id; always HTTP
48
+ GreetingServer: "http://greetings:3000/api/GreetingServer"
49
+ defaultEndpoint: "http://gateway:3000{rpcPath}/{serviceIdentifier}"
50
+ ```
51
+
52
+ `{rpcPath}` and `{serviceIdentifier}` are replaced. Without either, a browser uses `location`; a backend without them fails with `EndpointNotFoundError`.
53
+
54
+ ## WebSocket
55
+
56
+ ```yaml
57
+ rpc:
58
+ transport: websocket # default http
59
+ ```
60
+
61
+ Proxies then call the services without their own `rpc.endpoint` over one WebSocket connection per client, at `/<rpc.path>/ws` (methods are `<service>/<method>`). Each call passes the middlewares like an HTTP call, with the headers and cookies of the connection's upgrade request, so sessions and `@celljs/security` apply. While no connection can be made (an old browser, a platform without WebSocket support such as the serverless presets, a proxy that drops upgrades) calls go over HTTP, and the client tries again later; a connection that drops answers its pending calls with `RpcError` code `-32003` (they are not sent again: they may have run).
62
+
63
+ The backend calls the frontend through the connection of a call, or any open connection:
64
+
65
+ ```ts
66
+ // src/common/notice-protocol.ts
67
+ export const NoticeClient = Symbol('NoticeClient');
68
+ export interface NoticeClient {
69
+ notify(text: string): Promise<void>;
70
+ }
71
+
72
+ // src/browser/notice-client.ts (imported by src/browser/module.ts)
73
+ import { RpcClient } from '@celljs/rpc';
74
+
75
+ @RpcClient(NoticeClient)
76
+ export class NoticeClientImpl implements NoticeClient {
77
+ async notify(text: string) { /* show it */ }
78
+ }
79
+
80
+ // src/node/order-server.ts
81
+ import { Autowired } from '@celljs/core';
82
+ import { Rpc } from '@celljs/rpc';
83
+ import { RpcConnectionManager, RpcContext } from '@celljs/rpc/lib/node';
84
+
85
+ @Rpc(OrderServer)
86
+ export class OrderServerImpl implements OrderServer {
87
+ @Autowired(RpcConnectionManager)
88
+ protected readonly connections: RpcConnectionManager;
89
+
90
+ async watch(): Promise<void> {
91
+ const connection = RpcContext.requireConnection(); // the caller's connection
92
+ connection.onClose(() => { /* stop watching */ });
93
+ await connection.client<NoticeClient>(NoticeClient).notify('watching');
94
+ }
95
+
96
+ async announce(text: string): Promise<void> {
97
+ await Promise.all(this.connections.connections.map(c => c.client<NoticeClient>(NoticeClient).notify(text)));
98
+ }
99
+ }
100
+ ```
101
+
102
+ With `@RpcClient` components the frontend opens the connection as it starts and reopens it when it drops. `RpcContext.connection()` is undefined for a call over HTTP; `requireConnection()` then throws `RpcNoConnectionError` (400, `CELL_RPC_NO_CONNECTION`). Calls to a client time out after `rpc.websocket.callTimeout`; a closed connection rejects them.
103
+
104
+ | Key | Default | |
105
+ | --- | --- | --- |
106
+ | `rpc.websocket.allowedOrigins` | | Origins besides the server's own whose pages may connect, or `*`. Browsers send the cookies of the server with a WebSocket request from any page, so other origins are refused (403) |
107
+ | `rpc.websocket.maxPayload` | `1048576` | Largest message in bytes; a larger one closes the connection (1009) |
108
+ | `rpc.websocket.heartbeat` | `30000` | Milliseconds between pings of the server; a client that answers none is dropped |
109
+ | `rpc.websocket.callTimeout` | `30000` | Milliseconds a call waits for its answer |
110
+ | `rpc.websocket.reconnectDelay` | `1000` | Milliseconds before a client tries again; doubles up to 30 s |
111
+ | `rpc.websocket.endpoint` | the page's origin | `ws://` / `wss://` URL to connect to; needed by a backend calling another backend over WebSocket |
112
+
113
+ The server side is part of the package (no dependency); it needs a runtime whose `node:http` hands over upgrades: Node.js, Deno, and Bun 1.4 or later (older Bun versions log a warning and the clients use HTTP).
114
+
115
+ ## Batching
116
+
117
+ Over HTTP, `rpc.merge.enabled: true` makes the proxies send the calls made within `timerDelay` (35 ms) in one request (a JSON-RPC batch), up to `maxCount` calls or `maxLength` bytes.
@@ -0,0 +1,100 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "properties": {
4
+ "rpc": {
5
+ "type": "object",
6
+ "description": "Remote procedure calls between frontend and backend.",
7
+ "properties": {
8
+ "path": {
9
+ "type": "string",
10
+ "description": "Path of the RPC endpoint, under server.path."
11
+ },
12
+ "endpoint": {
13
+ "type": "object",
14
+ "description": "Endpoint URL by service identifier.",
15
+ "additionalProperties": {
16
+ "type": "string"
17
+ }
18
+ },
19
+ "defaultEndpoint": {
20
+ "type": "string",
21
+ "description": "Endpoint URL of services without their own."
22
+ },
23
+ "client": {
24
+ "type": "object",
25
+ "properties": {
26
+ "config": {
27
+ "type": "object",
28
+ "description": "Request options of the RPC client.",
29
+ "additionalProperties": true
30
+ }
31
+ }
32
+ },
33
+ "merge": {
34
+ "type": "object",
35
+ "properties": {
36
+ "enabled": {
37
+ "type": "boolean",
38
+ "description": "Merge RPC calls made close together into one request."
39
+ },
40
+ "timerDelay": {
41
+ "type": "integer",
42
+ "description": "Milliseconds to wait for more calls."
43
+ },
44
+ "maxLength": {
45
+ "type": "integer",
46
+ "description": "Largest merged request, in bytes."
47
+ },
48
+ "maxCount": {
49
+ "type": "integer",
50
+ "description": "Most calls in one merged request."
51
+ }
52
+ }
53
+ },
54
+ "transport": {
55
+ "type": "string",
56
+ "enum": [
57
+ "http",
58
+ "websocket"
59
+ ],
60
+ "description": "How proxies call services: http (default), or websocket, one connection per client that the server can also call back over (@RpcClient); calls fall back to HTTP while no connection can be made."
61
+ },
62
+ "websocket": {
63
+ "type": "object",
64
+ "description": "The WebSocket endpoint /<rpc.path>/ws (rpc.transport: websocket).",
65
+ "properties": {
66
+ "endpoint": {
67
+ "type": "string",
68
+ "description": "URL a client connects to (ws:// or wss://); default the page's origin. Needed by backends that call another backend over WebSocket."
69
+ },
70
+ "allowedOrigins": {
71
+ "type": "array",
72
+ "items": {
73
+ "type": "string"
74
+ },
75
+ "description": "Origins besides the server's own whose pages may connect, or \"*\"."
76
+ },
77
+ "maxPayload": {
78
+ "type": "integer",
79
+ "description": "Largest message, in bytes."
80
+ },
81
+ "heartbeat": {
82
+ "type": "integer",
83
+ "description": "Milliseconds between pings of the server; 0 disables them."
84
+ },
85
+ "callTimeout": {
86
+ "type": "integer",
87
+ "description": "Milliseconds a call waits for its answer."
88
+ },
89
+ "reconnectDelay": {
90
+ "type": "integer",
91
+ "description": "Milliseconds before a client reconnects; doubles up to 30 s."
92
+ }
93
+ },
94
+ "additionalProperties": false
95
+ }
96
+ },
97
+ "x-cell-public": true
98
+ }
99
+ }
100
+ }
package/cell.yml CHANGED
@@ -1,8 +1,12 @@
1
- cell:
2
- rpc:
3
- path: api
4
- merge:
5
- enabled: false
6
- timerDelay: 35 # 35ms
7
- maxLength: 5242880 # 5MB
8
- maxCount: 100
1
+ rpc:
2
+ path: api
3
+ transport: http # http | websocket
4
+ websocket:
5
+ maxPayload: 1048576 # bytes
6
+ heartbeat: 30000 # ms
7
+ callTimeout: 30000 # ms, calls of the server to a client
8
+ merge:
9
+ enabled: false
10
+ timerDelay: 35 # ms
11
+ maxLength: 5242880 # 5MB
12
+ maxCount: 100
@@ -1,2 +1,4 @@
1
+ export * from './rpc-protocol.js';
1
2
  export * from './rpc.js';
3
+ export * from './rpc-client.js';
2
4
  export * from './autorpc.js';
@@ -1,3 +1,5 @@
1
+ export * from './rpc-protocol.js';
1
2
  export * from './rpc.js';
3
+ export * from './rpc-client.js';
2
4
  export * from './autorpc.js';
3
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/annotation/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/annotation/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { ComponentDecorator } from '@celljs/core';
2
+ /**
3
+ * A component of the frontend (or of a backend calling another one) that the backend calls over the
4
+ * WebSocket connection: `RpcConnection.client<T>(id)` on the server is a proxy of it. Needs
5
+ * `rpc.transport: websocket`.
6
+ */
7
+ export declare const RpcClient: ComponentDecorator;
@@ -0,0 +1,18 @@
1
+ import { applyComponentDecorator, parseComponentOption } from '@celljs/core';
2
+ import { RPC_CLIENT } from '../client/client-protocol.js';
3
+ import { RpcUtil } from '../utils/rpc-util.js';
4
+ /**
5
+ * A component of the frontend (or of a backend calling another one) that the backend calls over the
6
+ * WebSocket connection: `RpcConnection.client<T>(id)` on the server is a proxy of it. Needs
7
+ * `rpc.transport: websocket`.
8
+ */
9
+ export const RpcClient = function (...idOrOption) {
10
+ return target => {
11
+ var _a;
12
+ const { ids } = applyComponentDecorator(parseComponentOption(target, idOrOption), target);
13
+ const id = (_a = ids[1]) !== null && _a !== void 0 ? _a : ids[0];
14
+ const path = RpcUtil.toPath(id);
15
+ applyComponentDecorator({ id: RPC_CLIENT, onActivation: ({ container }) => ({ path, get: () => container.get(id) }) }, target);
16
+ };
17
+ };
18
+ //# sourceMappingURL=rpc-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/common/annotation/rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAuB,UAAU,GAAG,UAAe;IACrE,OAAO,MAAM,CAAC,EAAE;;QACZ,MAAM,EAAE,GAAG,EAAE,GAAG,uBAAuB,CAAC,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1F,MAAM,EAAE,SAAG,GAAG,CAAC,CAAC,CAAC,mCAAI,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChC,uBAAuB,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACnI,CAAC,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const RPC_SERVICE: unique symbol;
2
+ /** Registered by `@Rpc(id)`: the path of the service, and the component. */
3
+ export interface RpcServiceMetadata {
4
+ path: string;
5
+ id: import('@celljs/core').ComponentId;
6
+ get(): object;
7
+ }
@@ -0,0 +1,2 @@
1
+ export const RPC_SERVICE = Symbol('RPC_SERVICE');
2
+ //# sourceMappingURL=rpc-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-protocol.js","sourceRoot":"","sources":["../../../src/common/annotation/rpc-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC"}
@@ -1,5 +1,9 @@
1
1
  import { ComponentDecorator, ComponentOption } from '@celljs/core';
2
2
  export declare const RPC_TAG = "Rpc";
3
+ /**
4
+ * An RPC service: a component (it takes the options of `@Component`) whose methods are called with
5
+ * JSON-RPC at `POST /<rpc.path>/<id>` and over the WebSocket connection (`<id>/<method>`).
6
+ */
3
7
  export declare const Rpc: ComponentDecorator;
4
8
  export declare function parseRpcOption(target: any, idOrOption: any): {
5
9
  id?: import("@celljs/core").ComponentId | import("@celljs/core").ComponentId[];
@@ -1,9 +1,12 @@
1
- import { applyComponentDecorator, parseComponentOption, Logger } from '@celljs/core';
2
- import { AOP_POINTCUT, PipeManager } from '@celljs/web';
3
- import { ConnectionHandler } from '../handler/index.js';
4
- import { JsonRpcConnectionHandler } from '../factory/index.js';
5
- import { RpcUtil, ConverterUtil } from '../utils/index.js';
1
+ import { applyComponentDecorator, parseComponentOption } from '@celljs/core';
2
+ import { AOP_POINTCUT } from '@celljs/web';
3
+ import { RpcUtil } from '../utils/rpc-util.js';
4
+ import { RPC_SERVICE } from './rpc-protocol.js';
6
5
  export const RPC_TAG = 'Rpc';
6
+ /**
7
+ * An RPC service: a component (it takes the options of `@Component`) whose methods are called with
8
+ * JSON-RPC at `POST /<rpc.path>/<id>` and over the WebSocket connection (`<id>/<method>`).
9
+ */
7
10
  export const Rpc = function (...idOrOption) {
8
11
  return target => {
9
12
  const option = parseRpcOption(target, idOrOption);
@@ -11,26 +14,19 @@ export const Rpc = function (...idOrOption) {
11
14
  };
12
15
  };
13
16
  export function parseRpcOption(target, idOrOption) {
17
+ var _a;
14
18
  const parsed = parseComponentOption(target, idOrOption);
15
- if (idOrOption[0].proxy === undefined) {
19
+ if (((_a = idOrOption[0]) === null || _a === void 0 ? void 0 : _a.proxy) === undefined) {
16
20
  parsed.proxy = true;
17
21
  }
18
22
  parsed.sysTags.push(AOP_POINTCUT, RPC_TAG);
19
23
  return parsed;
20
24
  }
21
25
  export function applyRpcDecorator(option, target) {
26
+ var _a;
22
27
  const { ids } = applyComponentDecorator(option, target);
23
- const id = ids[1] || ids[0];
24
- return applyComponentDecorator({ id: ConnectionHandler, onActivation: context => {
25
- const t = context.container.get(id);
26
- const pipeManager = context.container.get(PipeManager);
27
- const logger = context.container.get(Logger);
28
- const errorConverters = ConverterUtil.getGlobalErrorConverters(context.container);
29
- const errorConverter = ConverterUtil.getErrorConverters(id, context.container);
30
- if (errorConverter) {
31
- errorConverters.push(errorConverter);
32
- }
33
- return new JsonRpcConnectionHandler(RpcUtil.toPath(id), () => t, errorConverters, pipeManager, logger);
34
- } }, target);
28
+ const id = (_a = ids[1]) !== null && _a !== void 0 ? _a : ids[0];
29
+ const path = RpcUtil.toPath(id);
30
+ return applyComponentDecorator({ id: RPC_SERVICE, onActivation: ({ container }) => ({ path, id, get: () => container.get(id) }) }, target);
35
31
  }
36
32
  //# sourceMappingURL=rpc.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/common/annotation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AM,EAAE,UAAU,CAAC,CAAC;QAClD,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC;AACN,CAAC,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,UAAe;;IACvD,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxD,IAAI,CAAA,MAAA,UAAU,CAAC,CAAC,CAAC,0CAAE,KAAK,MAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;IACxB,CAAC;IACD,MAAM,CAAC,OAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAuB,EAAE,MAAW;;IAClE,MAAM,EAAE,GAAG,EAAE,GAAG,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxD,MAAM,EAAE,SAAG,GAAG,CAAC,CAAC,CAAC,mCAAI,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAChC,OAAO,uBAAuB,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/I,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const RPC_CLIENT: unique symbol;
2
+ /** Registered by `@RpcClient(id)`: the path the backend calls it by, and the component. */
3
+ export interface RpcClientMetadata {
4
+ path: string;
5
+ get(): object;
6
+ }
@@ -0,0 +1,2 @@
1
+ export const RPC_CLIENT = Symbol('RPC_CLIENT');
2
+ //# sourceMappingURL=client-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-protocol.js","sourceRoot":"","sources":["../../../src/common/client/client-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './client-protocol.js';
2
+ export * from './rpc-client-registry.js';
@@ -0,0 +1,3 @@
1
+ export * from './client-protocol.js';
2
+ export * from './rpc-client-registry.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { JsonRpc } from '../protocol/index.js';
2
+ import { RpcClientMetadata } from './client-protocol.js';
3
+ export declare const RpcClientRegistry: unique symbol;
4
+ /** The `@RpcClient` components, which answer the calls a backend makes over the WebSocket connection. */
5
+ export interface RpcClientRegistry {
6
+ readonly empty: boolean;
7
+ /** The response to a request of the server (`<client>/<method>`). */
8
+ handle(request: JsonRpc.Request): Promise<JsonRpc.Response>;
9
+ }
10
+ export declare class RpcClientRegistryImpl implements RpcClientRegistry {
11
+ protected readonly clients: RpcClientMetadata[];
12
+ get empty(): boolean;
13
+ handle(request: JsonRpc.Request): Promise<JsonRpc.Response>;
14
+ }
@@ -0,0 +1,51 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Autowired, Component, Optional } from '@celljs/core';
11
+ import { JsonRpc } from '../protocol/index.js';
12
+ import { RpcMethodUtil } from '../utils/rpc-method-util.js';
13
+ import { RPC_CLIENT } from './client-protocol.js';
14
+ export const RpcClientRegistry = Symbol('RpcClientRegistry');
15
+ let RpcClientRegistryImpl = class RpcClientRegistryImpl {
16
+ constructor() {
17
+ this.clients = [];
18
+ }
19
+ get empty() {
20
+ return this.clients.length === 0;
21
+ }
22
+ async handle(request) {
23
+ var _a, _b;
24
+ const id = (_a = request.id) !== null && _a !== void 0 ? _a : null;
25
+ const parts = RpcMethodUtil.split(request.method);
26
+ const metadata = parts && this.clients.find(c => c.path === parts[0]);
27
+ if (!parts || !metadata) {
28
+ return JsonRpc.error(id, JsonRpc.METHOD_NOT_FOUND, `No @RpcClient for ${request.method}.`);
29
+ }
30
+ const client = metadata.get();
31
+ if (!RpcMethodUtil.callable(client, parts[1])) {
32
+ return JsonRpc.error(id, JsonRpc.METHOD_NOT_FOUND, `${parts[0]} has no method ${parts[1]}.`);
33
+ }
34
+ try {
35
+ return JsonRpc.result(id, await client[parts[1]](...((_b = request.params) !== null && _b !== void 0 ? _b : [])));
36
+ }
37
+ catch (error) {
38
+ return JsonRpc.error(id, JsonRpc.SERVER_ERROR, error instanceof Error ? error.message : String(error));
39
+ }
40
+ }
41
+ };
42
+ __decorate([
43
+ Autowired(RPC_CLIENT),
44
+ Optional(),
45
+ __metadata("design:type", Array)
46
+ ], RpcClientRegistryImpl.prototype, "clients", void 0);
47
+ RpcClientRegistryImpl = __decorate([
48
+ Component(RpcClientRegistry)
49
+ ], RpcClientRegistryImpl);
50
+ export { RpcClientRegistryImpl };
51
+ //# sourceMappingURL=rpc-client-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc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;YAC5C,OAAO,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,gBAAgB,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,kBAAkB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjG,CAAC;QACD,IAAI,CAAC;YACD,OAAO,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAC,OAAO,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACjF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,YAAY,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3G,CAAC;IACL,CAAC;CACJ,CAAA;AAvBsB;IADlB,SAAS,CAAC,UAAU,CAAC;IAAE,QAAQ,EAAE;;sDACmB;AAH5C,qBAAqB;IADjC,SAAS,CAAC,iBAAiB,CAAC;GAChB,qBAAqB,CA0BjC"}
@@ -1 +1,3 @@
1
- export declare const RPC_PATH = "cell.rpc.path";
1
+ export declare const RPC_PATH = "rpc.path";
2
+ /** The WebSocket endpoint, below `rpc.path`. */
3
+ export declare const RPC_WEBSOCKET_PATH = "ws";
@@ -1,2 +1,4 @@
1
- export const RPC_PATH = 'cell.rpc.path';
1
+ export const RPC_PATH = 'rpc.path';
2
+ /** The WebSocket endpoint, below `rpc.path`. */
3
+ export const RPC_WEBSOCKET_PATH = 'ws';
2
4
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;AAEnC,gDAAgD;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC"}
@@ -1,6 +1,10 @@
1
+ import { JsonRpc } from '../protocol/index.js';
1
2
  export declare const ErrorConverter: unique symbol;
3
+ /** Named `GlobalConverter`, an `ErrorConverter` applies to every service; named after a service id, to that one. */
2
4
  export declare const GlobalConverter: unique symbol;
3
5
  export interface ErrorConverter {
4
- serialize(e: any): any;
5
- deserialize(e: any): any;
6
+ /** Server: the JSON-RPC error for an error a service threw, or undefined for the default. */
7
+ serialize(error: unknown): JsonRpc.ErrorObject | undefined;
8
+ /** Client: the error to throw for the error of a response, or undefined to keep it. */
9
+ deserialize(error: Error): Error | undefined;
6
10
  }
@@ -1,3 +1,4 @@
1
1
  export const ErrorConverter = Symbol('ErrorConverter');
2
+ /** Named `GlobalConverter`, an `ErrorConverter` applies to every service; named after a service id, to that one. */
2
3
  export const GlobalConverter = Symbol('GlobalConverter');
3
4
  //# sourceMappingURL=converter-protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"converter-protocol.js","sourceRoot":"","sources":["../../../src/common/converter/converter-protocol.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC"}
1
+ {"version":3,"file":"converter-protocol.js","sourceRoot":"","sources":["../../../src/common/converter/converter-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEvD,oHAAoH;AACpH,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC"}
@@ -1,4 +1,7 @@
1
1
  export declare const EndpointResolver: unique symbol;
2
2
  export interface EndpointResolver {
3
+ /** The HTTP URL of a service. */
3
4
  resolve(serviceIdentifier: string): Promise<string>;
5
+ /** The URL of the WebSocket endpoint: `rpc.websocket.endpoint`, or `/<rpc.path>/ws` of the page's origin. */
6
+ resolveWebSocket?(): Promise<string>;
4
7
  }
@@ -6,7 +6,9 @@ export declare class EndpointResolverImpl implements EndpointResolver {
6
6
  };
7
7
  protected readonly defaultEndpoint?: string;
8
8
  protected readonly rpcPath: string;
9
+ protected readonly websocketEndpoint?: string;
9
10
  protected pathResolver: PathResolver;
10
11
  protected parsed: Map<string, string>;
11
12
  resolve(serviceIdentifier: string): Promise<string>;
13
+ resolveWebSocket(): Promise<string>;
12
14
  }
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { Autowired, Component, Value } from '@celljs/core';
11
- import { RPC_PATH } from '../constants.js';
11
+ import { RPC_PATH, RPC_WEBSOCKET_PATH } from '../constants.js';
12
12
  import { PathResolver } from '@celljs/web';
13
13
  import { EndpointNotFoundError } from '../error/index.js';
14
14
  import { EndpointResolver } from './endpoint-protocol.js';
@@ -34,19 +34,33 @@ let EndpointResolverImpl = class EndpointResolverImpl {
34
34
  .replace(/{rpcPath}/g, await this.pathResolver.resolve(this.rpcPath))
35
35
  .replace(/{serviceIdentifier}/g, serviceIdentifier);
36
36
  }
37
+ async resolveWebSocket() {
38
+ if (this.websocketEndpoint) {
39
+ return this.websocketEndpoint.replace(/{rpcPath}/g, await this.pathResolver.resolve(this.rpcPath));
40
+ }
41
+ if (typeof location === 'undefined') {
42
+ throw new EndpointNotFoundError('rpc.websocket.endpoint');
43
+ }
44
+ const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
45
+ return `${protocol}//${location.host}${await this.pathResolver.resolve(this.rpcPath, RPC_WEBSOCKET_PATH)}`;
46
+ }
37
47
  };
38
48
  __decorate([
39
- Value('cell.rpc.endpoint'),
49
+ Value('rpc.endpoint'),
40
50
  __metadata("design:type", Object)
41
51
  ], EndpointResolverImpl.prototype, "endpoint", void 0);
42
52
  __decorate([
43
- Value('cell.rpc.defaultEndpoint'),
53
+ Value('rpc.defaultEndpoint'),
44
54
  __metadata("design:type", String)
45
55
  ], EndpointResolverImpl.prototype, "defaultEndpoint", void 0);
46
56
  __decorate([
47
57
  Value(RPC_PATH),
48
58
  __metadata("design:type", String)
49
59
  ], EndpointResolverImpl.prototype, "rpcPath", void 0);
60
+ __decorate([
61
+ Value('rpc.websocket.endpoint'),
62
+ __metadata("design:type", String)
63
+ ], EndpointResolverImpl.prototype, "websocketEndpoint", void 0);
50
64
  __decorate([
51
65
  Autowired(PathResolver),
52
66
  __metadata("design:type", Object)
@@ -1 +1 @@
1
- {"version":3,"file":"endpoint-resolver.js","sourceRoot":"","sources":["../../../src/common/endpoint/endpoint-resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGhD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAgB7B,KAAK,CAAC,OAAO,CAAC,iBAAyB;QACnC,IAAI,MAA0B,CAAC;QAC/B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACtC,MAAM,GAAG,iBAAiB,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,MA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