@restatedev/restate-sdk 0.8.1 → 0.9.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 (374) hide show
  1. package/dist/{clients → src/clients}/workflow_client.d.ts +2 -2
  2. package/dist/src/clients/workflow_client.d.ts.map +1 -0
  3. package/dist/{clients → src/clients}/workflow_client.js +2 -2
  4. package/dist/src/clients/workflow_client.js.map +1 -0
  5. package/dist/{connection → src/connection}/buffered_connection.d.ts +1 -0
  6. package/dist/src/connection/buffered_connection.d.ts.map +1 -0
  7. package/dist/src/connection/buffered_connection.js.map +1 -0
  8. package/dist/src/connection/connection.d.ts.map +1 -0
  9. package/dist/src/connection/connection.js.map +1 -0
  10. package/dist/{connection → src/connection}/http_connection.d.ts +1 -1
  11. package/dist/src/connection/http_connection.d.ts.map +1 -0
  12. package/dist/{connection → src/connection}/http_connection.js +1 -1
  13. package/dist/src/connection/http_connection.js.map +1 -0
  14. package/dist/{connection → src/connection}/lambda_connection.d.ts +1 -0
  15. package/dist/src/connection/lambda_connection.d.ts.map +1 -0
  16. package/dist/{connection → src/connection}/lambda_connection.js +5 -4
  17. package/dist/src/connection/lambda_connection.js.map +1 -0
  18. package/dist/{context.d.ts → src/context.d.ts} +146 -224
  19. package/dist/src/context.d.ts.map +1 -0
  20. package/dist/{context.js → src/context.js} +6 -41
  21. package/dist/src/context.js.map +1 -0
  22. package/dist/src/context_impl.d.ts +62 -0
  23. package/dist/src/context_impl.d.ts.map +1 -0
  24. package/dist/{context_impl.js → src/context_impl.js} +201 -182
  25. package/dist/src/context_impl.js.map +1 -0
  26. package/dist/src/endpoint/endpoint_impl.d.ts +28 -0
  27. package/dist/src/endpoint/endpoint_impl.d.ts.map +1 -0
  28. package/dist/src/endpoint/endpoint_impl.js +164 -0
  29. package/dist/src/endpoint/endpoint_impl.js.map +1 -0
  30. package/dist/{endpoint → src/endpoint}/http2_handler.d.ts +1 -1
  31. package/dist/src/endpoint/http2_handler.d.ts.map +1 -0
  32. package/dist/src/endpoint/http2_handler.js +153 -0
  33. package/dist/src/endpoint/http2_handler.js.map +1 -0
  34. package/dist/{endpoint → src/endpoint}/lambda_handler.d.ts +2 -2
  35. package/dist/src/endpoint/lambda_handler.d.ts.map +1 -0
  36. package/dist/{endpoint → src/endpoint}/lambda_handler.js +66 -56
  37. package/dist/src/endpoint/lambda_handler.js.map +1 -0
  38. package/dist/src/endpoint/request_signing/basex.d.ts +10 -0
  39. package/dist/src/endpoint/request_signing/basex.d.ts.map +1 -0
  40. package/dist/src/endpoint/request_signing/basex.js +138 -0
  41. package/dist/src/endpoint/request_signing/basex.js.map +1 -0
  42. package/dist/src/endpoint/request_signing/ed25519.d.ts +17 -0
  43. package/dist/src/endpoint/request_signing/ed25519.d.ts.map +1 -0
  44. package/dist/src/endpoint/request_signing/ed25519.js +78 -0
  45. package/dist/src/endpoint/request_signing/ed25519.js.map +1 -0
  46. package/dist/src/endpoint/request_signing/v1.d.ts +9 -0
  47. package/dist/src/endpoint/request_signing/v1.d.ts.map +1 -0
  48. package/dist/src/endpoint/request_signing/v1.js +148 -0
  49. package/dist/src/endpoint/request_signing/v1.js.map +1 -0
  50. package/dist/src/endpoint/request_signing/validate.d.ts +18 -0
  51. package/dist/src/endpoint/request_signing/validate.d.ts.map +1 -0
  52. package/dist/src/endpoint/request_signing/validate.js +45 -0
  53. package/dist/src/endpoint/request_signing/validate.js.map +1 -0
  54. package/dist/src/endpoint.d.ts +102 -0
  55. package/dist/src/endpoint.d.ts.map +1 -0
  56. package/dist/{endpoint.js → src/endpoint.js} +1 -1
  57. package/dist/src/endpoint.js.map +1 -0
  58. package/dist/src/generated/proto/javascript_pb.d.ts +26 -0
  59. package/dist/src/generated/proto/javascript_pb.d.ts.map +1 -0
  60. package/dist/src/generated/proto/javascript_pb.js +52 -0
  61. package/dist/src/generated/proto/javascript_pb.js.map +1 -0
  62. package/dist/src/generated/proto/protocol_pb.d.ts +865 -0
  63. package/dist/src/generated/proto/protocol_pb.d.ts.map +1 -0
  64. package/dist/src/generated/proto/protocol_pb.js +1112 -0
  65. package/dist/src/generated/proto/protocol_pb.js.map +1 -0
  66. package/dist/src/generated/version.d.ts +2 -0
  67. package/dist/src/generated/version.d.ts.map +1 -0
  68. package/dist/src/generated/version.js +5 -0
  69. package/dist/src/generated/version.js.map +1 -0
  70. package/dist/{invocation.d.ts → src/invocation.d.ts} +14 -18
  71. package/dist/src/invocation.d.ts.map +1 -0
  72. package/dist/{invocation.js → src/invocation.js} +25 -24
  73. package/dist/src/invocation.js.map +1 -0
  74. package/dist/{io → src/io}/decoder.d.ts +3 -2
  75. package/dist/src/io/decoder.d.ts.map +1 -0
  76. package/dist/{io → src/io}/decoder.js +12 -10
  77. package/dist/src/io/decoder.js.map +1 -0
  78. package/dist/{io → src/io}/encoder.d.ts +1 -1
  79. package/dist/src/io/encoder.d.ts.map +1 -0
  80. package/dist/{io → src/io}/encoder.js +11 -21
  81. package/dist/src/io/encoder.js.map +1 -0
  82. package/dist/{journal.d.ts → src/journal.d.ts} +7 -7
  83. package/dist/src/journal.d.ts.map +1 -0
  84. package/dist/{journal.js → src/journal.js} +64 -46
  85. package/dist/src/journal.js.map +1 -0
  86. package/dist/{local_state_store.d.ts → src/local_state_store.d.ts} +2 -2
  87. package/dist/src/local_state_store.d.ts.map +1 -0
  88. package/dist/{local_state_store.js → src/local_state_store.js} +19 -17
  89. package/dist/src/local_state_store.js.map +1 -0
  90. package/dist/{logger.d.ts → src/logger.d.ts} +9 -1
  91. package/dist/src/logger.d.ts.map +1 -0
  92. package/dist/src/logger.js +158 -0
  93. package/dist/src/logger.js.map +1 -0
  94. package/dist/src/promise_combinator_tracker.d.ts.map +1 -0
  95. package/dist/src/promise_combinator_tracker.js.map +1 -0
  96. package/dist/src/public_api.d.ts +7 -0
  97. package/dist/src/public_api.d.ts.map +1 -0
  98. package/dist/{public_api.js → src/public_api.js} +4 -14
  99. package/dist/src/public_api.js.map +1 -0
  100. package/dist/{state_machine.d.ts → src/state_machine.d.ts} +7 -4
  101. package/dist/src/state_machine.d.ts.map +1 -0
  102. package/dist/{state_machine.js → src/state_machine.js} +32 -34
  103. package/dist/src/state_machine.js.map +1 -0
  104. package/dist/src/types/components.d.ts +65 -0
  105. package/dist/src/types/components.d.ts.map +1 -0
  106. package/dist/src/types/components.js +163 -0
  107. package/dist/src/types/components.js.map +1 -0
  108. package/dist/src/types/discovery.d.ts +40 -0
  109. package/dist/src/types/discovery.d.ts.map +1 -0
  110. package/dist/src/types/discovery.js +29 -0
  111. package/dist/src/types/discovery.js.map +1 -0
  112. package/dist/src/types/errors.d.ts +53 -0
  113. package/dist/src/types/errors.d.ts.map +1 -0
  114. package/dist/src/types/errors.js +129 -0
  115. package/dist/src/types/errors.js.map +1 -0
  116. package/dist/src/types/protocol.d.ts +33 -0
  117. package/dist/src/types/protocol.d.ts.map +1 -0
  118. package/dist/{types → src/types}/protocol.js +52 -52
  119. package/dist/src/types/protocol.js.map +1 -0
  120. package/dist/src/types/rpc.d.ts +50 -0
  121. package/dist/src/types/rpc.d.ts.map +1 -0
  122. package/dist/src/types/rpc.js +38 -0
  123. package/dist/src/types/rpc.js.map +1 -0
  124. package/dist/{types → src/types}/types.d.ts +0 -9
  125. package/dist/src/types/types.d.ts.map +1 -0
  126. package/dist/{types → src/types}/types.js +4 -21
  127. package/dist/src/types/types.js.map +1 -0
  128. package/dist/src/user_agent.d.ts +2 -0
  129. package/dist/src/user_agent.d.ts.map +1 -0
  130. package/dist/src/user_agent.js +16 -0
  131. package/dist/src/user_agent.js.map +1 -0
  132. package/dist/src/utils/message_logger.d.ts +7 -0
  133. package/dist/src/utils/message_logger.d.ts.map +1 -0
  134. package/dist/{utils → src/utils}/message_logger.js +17 -26
  135. package/dist/src/utils/message_logger.js.map +1 -0
  136. package/dist/src/utils/promises.d.ts.map +1 -0
  137. package/dist/src/utils/promises.js.map +1 -0
  138. package/dist/{utils → src/utils}/rand.d.ts +1 -0
  139. package/dist/src/utils/rand.d.ts.map +1 -0
  140. package/dist/{utils → src/utils}/rand.js +7 -6
  141. package/dist/src/utils/rand.js.map +1 -0
  142. package/dist/src/utils/serde.d.ts +3 -0
  143. package/dist/src/utils/serde.d.ts.map +1 -0
  144. package/dist/src/utils/serde.js +24 -0
  145. package/dist/src/utils/serde.js.map +1 -0
  146. package/dist/{utils → src/utils}/utils.d.ts +0 -1
  147. package/dist/src/utils/utils.d.ts.map +1 -0
  148. package/dist/{utils → src/utils}/utils.js +36 -43
  149. package/dist/src/utils/utils.js.map +1 -0
  150. package/dist/{workflows → src/workflows}/workflow.d.ts +6 -6
  151. package/dist/src/workflows/workflow.d.ts.map +1 -0
  152. package/dist/{workflows → src/workflows}/workflow.js +11 -7
  153. package/dist/src/workflows/workflow.js.map +1 -0
  154. package/dist/src/workflows/workflow_state_service.d.ts +35 -0
  155. package/dist/src/workflows/workflow_state_service.d.ts.map +1 -0
  156. package/dist/{workflows → src/workflows}/workflow_state_service.js +11 -11
  157. package/dist/src/workflows/workflow_state_service.js.map +1 -0
  158. package/dist/{workflows → src/workflows}/workflow_wrapper_service.d.ts +2 -2
  159. package/dist/src/workflows/workflow_wrapper_service.d.ts.map +1 -0
  160. package/dist/{workflows → src/workflows}/workflow_wrapper_service.js +66 -45
  161. package/dist/src/workflows/workflow_wrapper_service.js.map +1 -0
  162. package/dist/tsconfig.tsbuildinfo +1 -0
  163. package/package.json +13 -16
  164. package/LICENSE +0 -21
  165. package/README.md +0 -154
  166. package/dist/clients/workflow_client.d.ts.map +0 -1
  167. package/dist/clients/workflow_client.js.map +0 -1
  168. package/dist/connection/buffered_connection.d.ts.map +0 -1
  169. package/dist/connection/buffered_connection.js.map +0 -1
  170. package/dist/connection/connection.d.ts.map +0 -1
  171. package/dist/connection/connection.js.map +0 -1
  172. package/dist/connection/embedded_connection.d.ts +0 -20
  173. package/dist/connection/embedded_connection.d.ts.map +0 -1
  174. package/dist/connection/embedded_connection.js +0 -59
  175. package/dist/connection/embedded_connection.js.map +0 -1
  176. package/dist/connection/http_connection.d.ts.map +0 -1
  177. package/dist/connection/http_connection.js.map +0 -1
  178. package/dist/connection/lambda_connection.d.ts.map +0 -1
  179. package/dist/connection/lambda_connection.js.map +0 -1
  180. package/dist/context.d.ts.map +0 -1
  181. package/dist/context.js.map +0 -1
  182. package/dist/context_impl.d.ts +0 -65
  183. package/dist/context_impl.d.ts.map +0 -1
  184. package/dist/context_impl.js.map +0 -1
  185. package/dist/embedded/api.d.ts +0 -27
  186. package/dist/embedded/api.d.ts.map +0 -1
  187. package/dist/embedded/api.js +0 -35
  188. package/dist/embedded/api.js.map +0 -1
  189. package/dist/embedded/handler.d.ts +0 -4
  190. package/dist/embedded/handler.d.ts.map +0 -1
  191. package/dist/embedded/handler.js +0 -26
  192. package/dist/embedded/handler.js.map +0 -1
  193. package/dist/embedded/http2_remote.d.ts +0 -11
  194. package/dist/embedded/http2_remote.d.ts.map +0 -1
  195. package/dist/embedded/http2_remote.js +0 -91
  196. package/dist/embedded/http2_remote.js.map +0 -1
  197. package/dist/embedded/invocation.d.ts +0 -5
  198. package/dist/embedded/invocation.d.ts.map +0 -1
  199. package/dist/embedded/invocation.js +0 -94
  200. package/dist/embedded/invocation.js.map +0 -1
  201. package/dist/endpoint/endpoint_impl.d.ts +0 -35
  202. package/dist/endpoint/endpoint_impl.d.ts.map +0 -1
  203. package/dist/endpoint/endpoint_impl.js +0 -405
  204. package/dist/endpoint/endpoint_impl.js.map +0 -1
  205. package/dist/endpoint/http2_handler.d.ts.map +0 -1
  206. package/dist/endpoint/http2_handler.js +0 -119
  207. package/dist/endpoint/http2_handler.js.map +0 -1
  208. package/dist/endpoint/lambda_handler.d.ts.map +0 -1
  209. package/dist/endpoint/lambda_handler.js.map +0 -1
  210. package/dist/endpoint.d.ts +0 -161
  211. package/dist/endpoint.d.ts.map +0 -1
  212. package/dist/endpoint.js.map +0 -1
  213. package/dist/generated/dev/restate/events.d.ts +0 -96
  214. package/dist/generated/dev/restate/events.d.ts.map +0 -1
  215. package/dist/generated/dev/restate/events.js +0 -371
  216. package/dist/generated/dev/restate/events.js.map +0 -1
  217. package/dist/generated/dev/restate/ext.d.ts +0 -91
  218. package/dist/generated/dev/restate/ext.d.ts.map +0 -1
  219. package/dist/generated/dev/restate/ext.js +0 -215
  220. package/dist/generated/dev/restate/ext.js.map +0 -1
  221. package/dist/generated/google/protobuf/descriptor.d.ts +0 -1204
  222. package/dist/generated/google/protobuf/descriptor.d.ts.map +0 -1
  223. package/dist/generated/google/protobuf/descriptor.js +0 -6676
  224. package/dist/generated/google/protobuf/descriptor.js.map +0 -1
  225. package/dist/generated/google/protobuf/empty.d.ts +0 -86
  226. package/dist/generated/google/protobuf/empty.d.ts.map +0 -1
  227. package/dist/generated/google/protobuf/empty.js +0 -107
  228. package/dist/generated/google/protobuf/empty.js.map +0 -1
  229. package/dist/generated/google/protobuf/struct.d.ts +0 -175
  230. package/dist/generated/google/protobuf/struct.d.ts.map +0 -1
  231. package/dist/generated/google/protobuf/struct.js +0 -754
  232. package/dist/generated/google/protobuf/struct.js.map +0 -1
  233. package/dist/generated/proto/discovery.d.ts +0 -105
  234. package/dist/generated/proto/discovery.d.ts.map +0 -1
  235. package/dist/generated/proto/discovery.js +0 -364
  236. package/dist/generated/proto/discovery.js.map +0 -1
  237. package/dist/generated/proto/dynrpc.d.ts +0 -150
  238. package/dist/generated/proto/dynrpc.d.ts.map +0 -1
  239. package/dist/generated/proto/dynrpc.js +0 -668
  240. package/dist/generated/proto/dynrpc.js.map +0 -1
  241. package/dist/generated/proto/javascript.d.ts +0 -110
  242. package/dist/generated/proto/javascript.d.ts.map +0 -1
  243. package/dist/generated/proto/javascript.js +0 -416
  244. package/dist/generated/proto/javascript.js.map +0 -1
  245. package/dist/generated/proto/protocol.d.ts +0 -450
  246. package/dist/generated/proto/protocol.d.ts.map +0 -1
  247. package/dist/generated/proto/protocol.js +0 -2641
  248. package/dist/generated/proto/protocol.js.map +0 -1
  249. package/dist/generated/proto/services.d.ts +0 -307
  250. package/dist/generated/proto/services.d.ts.map +0 -1
  251. package/dist/generated/proto/services.js +0 -1535
  252. package/dist/generated/proto/services.js.map +0 -1
  253. package/dist/generated/proto/test.d.ts +0 -116
  254. package/dist/generated/proto/test.d.ts.map +0 -1
  255. package/dist/generated/proto/test.js +0 -321
  256. package/dist/generated/proto/test.js.map +0 -1
  257. package/dist/invocation.d.ts.map +0 -1
  258. package/dist/invocation.js.map +0 -1
  259. package/dist/io/decoder.d.ts.map +0 -1
  260. package/dist/io/decoder.js.map +0 -1
  261. package/dist/io/encoder.d.ts.map +0 -1
  262. package/dist/io/encoder.js.map +0 -1
  263. package/dist/journal.d.ts.map +0 -1
  264. package/dist/journal.js.map +0 -1
  265. package/dist/local_state_store.d.ts.map +0 -1
  266. package/dist/local_state_store.js.map +0 -1
  267. package/dist/logger.d.ts.map +0 -1
  268. package/dist/logger.js +0 -90
  269. package/dist/logger.js.map +0 -1
  270. package/dist/promise_combinator_tracker.d.ts.map +0 -1
  271. package/dist/promise_combinator_tracker.js.map +0 -1
  272. package/dist/public_api.d.ts +0 -10
  273. package/dist/public_api.d.ts.map +0 -1
  274. package/dist/public_api.js.map +0 -1
  275. package/dist/state_machine.d.ts.map +0 -1
  276. package/dist/state_machine.js.map +0 -1
  277. package/dist/types/errors.d.ts +0 -188
  278. package/dist/types/errors.d.ts.map +0 -1
  279. package/dist/types/errors.js +0 -273
  280. package/dist/types/errors.js.map +0 -1
  281. package/dist/types/grpc.d.ts +0 -90
  282. package/dist/types/grpc.d.ts.map +0 -1
  283. package/dist/types/grpc.js +0 -81
  284. package/dist/types/grpc.js.map +0 -1
  285. package/dist/types/protocol.d.ts +0 -30
  286. package/dist/types/protocol.d.ts.map +0 -1
  287. package/dist/types/protocol.js.map +0 -1
  288. package/dist/types/router.d.ts +0 -33
  289. package/dist/types/router.d.ts.map +0 -1
  290. package/dist/types/router.js +0 -36
  291. package/dist/types/router.js.map +0 -1
  292. package/dist/types/types.d.ts.map +0 -1
  293. package/dist/types/types.js.map +0 -1
  294. package/dist/utils/assumptions.d.ts +0 -8
  295. package/dist/utils/assumptions.d.ts.map +0 -1
  296. package/dist/utils/assumptions.js +0 -101
  297. package/dist/utils/assumptions.js.map +0 -1
  298. package/dist/utils/message_logger.d.ts +0 -28
  299. package/dist/utils/message_logger.d.ts.map +0 -1
  300. package/dist/utils/message_logger.js.map +0 -1
  301. package/dist/utils/promises.d.ts.map +0 -1
  302. package/dist/utils/promises.js.map +0 -1
  303. package/dist/utils/public_utils.d.ts +0 -58
  304. package/dist/utils/public_utils.d.ts.map +0 -1
  305. package/dist/utils/public_utils.js +0 -49
  306. package/dist/utils/public_utils.js.map +0 -1
  307. package/dist/utils/rand.d.ts.map +0 -1
  308. package/dist/utils/rand.js.map +0 -1
  309. package/dist/utils/utils.d.ts.map +0 -1
  310. package/dist/utils/utils.js.map +0 -1
  311. package/dist/workflows/workflow.d.ts.map +0 -1
  312. package/dist/workflows/workflow.js.map +0 -1
  313. package/dist/workflows/workflow_state_service.d.ts +0 -35
  314. package/dist/workflows/workflow_state_service.d.ts.map +0 -1
  315. package/dist/workflows/workflow_state_service.js.map +0 -1
  316. package/dist/workflows/workflow_wrapper_service.d.ts.map +0 -1
  317. package/dist/workflows/workflow_wrapper_service.js.map +0 -1
  318. package/src/clients/workflow_client.ts +0 -290
  319. package/src/connection/buffered_connection.ts +0 -47
  320. package/src/connection/connection.ts +0 -34
  321. package/src/connection/embedded_connection.ts +0 -62
  322. package/src/connection/http_connection.ts +0 -228
  323. package/src/connection/lambda_connection.ts +0 -69
  324. package/src/context.ts +0 -633
  325. package/src/context_impl.ts +0 -721
  326. package/src/embedded/api.ts +0 -57
  327. package/src/embedded/handler.ts +0 -36
  328. package/src/embedded/http2_remote.ts +0 -103
  329. package/src/embedded/invocation.ts +0 -126
  330. package/src/endpoint/endpoint_impl.ts +0 -623
  331. package/src/endpoint/http2_handler.ts +0 -151
  332. package/src/endpoint/lambda_handler.ts +0 -181
  333. package/src/endpoint.ts +0 -187
  334. package/src/generated/dev/restate/events.ts +0 -430
  335. package/src/generated/dev/restate/ext.ts +0 -238
  336. package/src/generated/google/protobuf/descriptor.ts +0 -7889
  337. package/src/generated/google/protobuf/empty.ts +0 -150
  338. package/src/generated/google/protobuf/struct.ts +0 -878
  339. package/src/generated/proto/discovery.ts +0 -423
  340. package/src/generated/proto/dynrpc.ts +0 -768
  341. package/src/generated/proto/javascript.ts +0 -488
  342. package/src/generated/proto/protocol.ts +0 -3091
  343. package/src/generated/proto/services.ts +0 -1834
  344. package/src/generated/proto/test.ts +0 -387
  345. package/src/invocation.ts +0 -212
  346. package/src/io/decoder.ts +0 -171
  347. package/src/io/encoder.ts +0 -72
  348. package/src/journal.ts +0 -537
  349. package/src/local_state_store.ts +0 -94
  350. package/src/logger.ts +0 -121
  351. package/src/promise_combinator_tracker.ts +0 -191
  352. package/src/public_api.ts +0 -53
  353. package/src/state_machine.ts +0 -635
  354. package/src/types/errors.ts +0 -297
  355. package/src/types/grpc.ts +0 -97
  356. package/src/types/protocol.ts +0 -201
  357. package/src/types/router.ts +0 -118
  358. package/src/types/types.ts +0 -160
  359. package/src/utils/assumptions.ts +0 -131
  360. package/src/utils/message_logger.ts +0 -112
  361. package/src/utils/promises.ts +0 -118
  362. package/src/utils/public_utils.ts +0 -91
  363. package/src/utils/rand.ts +0 -142
  364. package/src/utils/utils.ts +0 -178
  365. package/src/workflows/workflow.ts +0 -178
  366. package/src/workflows/workflow_state_service.ts +0 -299
  367. package/src/workflows/workflow_wrapper_service.ts +0 -314
  368. /package/dist/{connection → src/connection}/buffered_connection.js +0 -0
  369. /package/dist/{connection → src/connection}/connection.d.ts +0 -0
  370. /package/dist/{connection → src/connection}/connection.js +0 -0
  371. /package/dist/{promise_combinator_tracker.d.ts → src/promise_combinator_tracker.d.ts} +0 -0
  372. /package/dist/{promise_combinator_tracker.js → src/promise_combinator_tracker.js} +0 -0
  373. /package/dist/{utils → src/utils}/promises.d.ts +0 -0
  374. /package/dist/{utils → src/utils}/promises.js +0 -0
@@ -10,29 +10,26 @@
10
10
  * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.ContextImpl = exports.CallContexType = void 0;
14
- const protocol_1 = require("./generated/proto/protocol");
15
- const protocol_2 = require("./types/protocol");
16
- const javascript_1 = require("./generated/proto/javascript");
17
- const async_hooks_1 = require("async_hooks");
13
+ exports.ContextImpl = exports.CallContextType = void 0;
14
+ const protocol_pb_1 = require("./generated/proto/protocol_pb");
15
+ const protocol_1 = require("./types/protocol");
16
+ const node_async_hooks_1 = require("node:async_hooks");
18
17
  const errors_1 = require("./types/errors");
19
18
  const utils_1 = require("./utils/utils");
20
- const public_utils_1 = require("./utils/public_utils");
21
- const dynrpc_1 = require("./generated/proto/dynrpc");
22
- const assumptions_1 = require("./utils/assumptions");
19
+ const protobuf_1 = require("@bufbuild/protobuf");
23
20
  const rand_1 = require("./utils/rand");
24
21
  const promise_combinator_tracker_1 = require("./promise_combinator_tracker");
25
- var CallContexType;
26
- (function (CallContexType) {
27
- CallContexType[CallContexType["None"] = 0] = "None";
28
- CallContexType[CallContexType["SideEffect"] = 1] = "SideEffect";
29
- CallContexType[CallContexType["OneWayCall"] = 2] = "OneWayCall";
30
- })(CallContexType = exports.CallContexType || (exports.CallContexType = {}));
22
+ const node_buffer_1 = require("node:buffer");
23
+ const serde_1 = require("./utils/serde");
24
+ var CallContextType;
25
+ (function (CallContextType) {
26
+ CallContextType[CallContextType["None"] = 0] = "None";
27
+ CallContextType[CallContextType["Run"] = 1] = "Run";
28
+ })(CallContextType = exports.CallContextType || (exports.CallContextType = {}));
31
29
  class ContextImpl {
32
- id;
33
- serviceName;
34
30
  console;
35
31
  keyedContext;
32
+ keyedContextKey;
36
33
  stateMachine;
37
34
  rand;
38
35
  // here, we capture the context information for actions on the Restate context that
@@ -41,19 +38,41 @@ class ContextImpl {
41
38
  // we also use this information to ensure we check that only allowed operations are
42
39
  // used. Within side-effects, no operations are allowed on the RestateContext.
43
40
  // For example, this is illegal: 'ctx.sideEffect(() => {await ctx.get("my-state")})'
44
- static callContext = new async_hooks_1.AsyncLocalStorage();
41
+ static callContext = new node_async_hooks_1.AsyncLocalStorage();
45
42
  // This is used to guard users against calling ctx.sideEffect without awaiting it.
46
43
  // See https://github.com/restatedev/sdk-typescript/issues/197 for more details.
47
- executingSideEffect = false;
48
- constructor(id, serviceName, console, keyedContext,
44
+ executingRun = false;
45
+ invocationRequest;
46
+ date = {
47
+ now: () => {
48
+ return this.run(() => Date.now());
49
+ },
50
+ toJSON: () => {
51
+ return this.run(() => new Date().toJSON());
52
+ },
53
+ };
54
+ constructor(id, console, keyedContext, keyedContextKey, invocationValue, invocationHeaders,
49
55
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
56
  stateMachine, rand = new rand_1.RandImpl(id)) {
51
- this.id = id;
52
- this.serviceName = serviceName;
53
57
  this.console = console;
54
58
  this.keyedContext = keyedContext;
59
+ this.keyedContextKey = keyedContextKey;
55
60
  this.stateMachine = stateMachine;
56
61
  this.rand = rand;
62
+ this.invocationRequest = {
63
+ id,
64
+ headers: invocationHeaders,
65
+ body: invocationValue,
66
+ };
67
+ }
68
+ get key() {
69
+ if (!this.keyedContextKey) {
70
+ throw new errors_1.TerminalError("unexpected missing key");
71
+ }
72
+ return this.keyedContextKey;
73
+ }
74
+ request() {
75
+ return this.invocationRequest;
57
76
  }
58
77
  // DON'T make this function async!!! see sideEffect comment for details.
59
78
  get(name) {
@@ -61,10 +80,10 @@ class ContextImpl {
61
80
  this.checkState("get state");
62
81
  this.checkStateOperation("get state");
63
82
  // Create the message and let the state machine process it
64
- const msg = protocol_1.GetStateEntryMessage.create({ key: Buffer.from(name) });
83
+ const msg = new protocol_pb_1.GetStateEntryMessage({ key: node_buffer_1.Buffer.from(name) });
65
84
  const completed = this.stateMachine.localStateStore.tryCompleteGet(name, msg);
66
85
  const getState = async () => {
67
- const result = await this.stateMachine.handleUserCodeMessage(protocol_2.GET_STATE_ENTRY_MESSAGE_TYPE, msg, completed);
86
+ const result = await this.stateMachine.handleUserCodeMessage(protocol_1.GET_STATE_ENTRY_MESSAGE_TYPE, msg, completed);
68
87
  // If the GetState message did not have a value or empty,
69
88
  // then we went to the runtime to get the value.
70
89
  // When we get the response, we set it in the localStateStore,
@@ -72,7 +91,7 @@ class ContextImpl {
72
91
  if (!completed) {
73
92
  this.stateMachine.localStateStore.add(name, result);
74
93
  }
75
- if (!(result instanceof Buffer)) {
94
+ if (!(result instanceof node_buffer_1.Buffer)) {
76
95
  return null;
77
96
  }
78
97
  return (0, utils_1.jsonDeserialize)(result.toString());
@@ -84,10 +103,10 @@ class ContextImpl {
84
103
  // Check if this is a valid action
85
104
  this.checkState("state keys");
86
105
  // Create the message and let the state machine process it
87
- const msg = protocol_1.GetStateKeysEntryMessage.create({});
106
+ const msg = new protocol_pb_1.GetStateKeysEntryMessage({});
88
107
  const completed = this.stateMachine.localStateStore.tryCompletedGetStateKeys(msg);
89
108
  const getStateKeys = async () => {
90
- const result = await this.stateMachine.handleUserCodeMessage(protocol_2.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE, msg, completed);
109
+ const result = await this.stateMachine.handleUserCodeMessage(protocol_1.GET_STATE_KEYS_ENTRY_MESSAGE_TYPE, msg, completed);
91
110
  return result.keys.map((b) => b.toString());
92
111
  };
93
112
  return getStateKeys();
@@ -96,133 +115,150 @@ class ContextImpl {
96
115
  this.checkState("set state");
97
116
  this.checkStateOperation("set state");
98
117
  const msg = this.stateMachine.localStateStore.set(name, value);
99
- this.stateMachine.handleUserCodeMessage(protocol_2.SET_STATE_ENTRY_MESSAGE_TYPE, msg);
118
+ this.stateMachine
119
+ .handleUserCodeMessage(protocol_1.SET_STATE_ENTRY_MESSAGE_TYPE, msg)
120
+ .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
100
121
  }
101
122
  clear(name) {
102
123
  this.checkState("clear state");
103
124
  this.checkStateOperation("clear state");
104
125
  const msg = this.stateMachine.localStateStore.clear(name);
105
- this.stateMachine.handleUserCodeMessage(protocol_2.CLEAR_STATE_ENTRY_MESSAGE_TYPE, msg);
126
+ this.stateMachine
127
+ .handleUserCodeMessage(protocol_1.CLEAR_STATE_ENTRY_MESSAGE_TYPE, msg)
128
+ .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
106
129
  }
107
130
  clearAll() {
108
131
  this.checkState("clear all state");
109
132
  const msg = this.stateMachine.localStateStore.clearAll();
110
- this.stateMachine.handleUserCodeMessage(protocol_2.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE, msg);
133
+ this.stateMachine
134
+ .handleUserCodeMessage(protocol_1.CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE, msg)
135
+ .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
111
136
  }
112
137
  // --- Calls, background calls, etc
113
- request(service, method, data) {
114
- if (this.isInOneWayCall()) {
115
- return this.invokeOneWay(service, method, data, this.getOneWayCallDelay());
116
- }
117
- else {
118
- return this.invoke(service, method, data);
119
- }
120
- }
121
138
  // DON'T make this function async!!! see sideEffect comment for details.
122
- invoke(service, method, data) {
139
+ invoke(service, method, data, key) {
123
140
  this.checkState("invoke");
124
- const msg = protocol_1.InvokeEntryMessage.create({
141
+ const msg = new protocol_pb_1.CallEntryMessage({
125
142
  serviceName: service,
126
- methodName: method,
127
- parameter: Buffer.from(data),
143
+ handlerName: method,
144
+ parameter: node_buffer_1.Buffer.from(data),
145
+ key,
128
146
  });
129
147
  return this.markCombineablePromise(this.stateMachine
130
- .handleUserCodeMessage(protocol_2.INVOKE_ENTRY_MESSAGE_TYPE, msg)
148
+ .handleUserCodeMessage(protocol_1.INVOKE_ENTRY_MESSAGE_TYPE, msg)
131
149
  .transform((v) => v));
132
150
  }
133
- async invokeOneWay(service, method, data, delay) {
151
+ async invokeOneWay(service, method, data, delay, key) {
134
152
  const actualDelay = delay || 0;
135
- const invokeTime = actualDelay > 0 ? Date.now() + actualDelay : undefined;
136
- const msg = protocol_1.BackgroundInvokeEntryMessage.create({
153
+ const invokeTime = actualDelay > 0 ? Date.now() + actualDelay : protobuf_1.protoInt64.zero;
154
+ const msg = new protocol_pb_1.OneWayCallEntryMessage({
137
155
  serviceName: service,
138
- methodName: method,
139
- parameter: Buffer.from(data),
140
- invokeTime: invokeTime,
156
+ handlerName: method,
157
+ parameter: node_buffer_1.Buffer.from(data),
158
+ invokeTime: protobuf_1.protoInt64.parse(invokeTime),
159
+ key,
141
160
  });
142
- await this.stateMachine.handleUserCodeMessage(protocol_2.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE, msg);
161
+ await this.stateMachine.handleUserCodeMessage(protocol_1.BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE, msg);
143
162
  return new Uint8Array();
144
163
  }
145
- // DON'T make this function async!!! see sideEffect comment for details.
146
- oneWayCall(
147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
- call) {
149
- this.checkState("oneWayCall");
150
- return ContextImpl.callContext.run({ type: CallContexType.OneWayCall }, call);
151
- }
152
- // DON'T make this function async!!! see sideEffect comment for details.
153
- delayedCall(
154
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
- call, delayMillis) {
156
- this.checkState("delayedCall");
157
- // Delayed call is a one way call with a delay
158
- return ContextImpl.callContext.run({ type: CallContexType.OneWayCall, delay: delayMillis }, call);
159
- }
160
- rpc({ path }) {
164
+ serviceClient({ name, }) {
161
165
  const clientProxy = new Proxy({}, {
162
166
  get: (_target, prop) => {
163
167
  const route = prop;
164
- return async (...args) => {
165
- const request = (0, assumptions_1.requestFromArgs)(args);
166
- const requestBytes = dynrpc_1.RpcRequest.encode(request).finish();
167
- return this.invoke(path, route, requestBytes).transform((responseBytes) => dynrpc_1.RpcResponse.decode(responseBytes).response);
168
+ return (...args) => {
169
+ const requestBytes = (0, serde_1.serializeJson)(args.shift());
170
+ return this.invoke(name, route, requestBytes).transform((responseBytes) => (0, serde_1.deserializeJson)(responseBytes));
168
171
  };
169
172
  },
170
173
  });
171
174
  return clientProxy;
172
175
  }
173
- send(options) {
174
- return this.sendDelayed(options, 0);
176
+ objectClient({ name }, key) {
177
+ const clientProxy = new Proxy({}, {
178
+ get: (_target, prop) => {
179
+ const route = prop;
180
+ return (...args) => {
181
+ const requestBytes = (0, serde_1.serializeJson)(args.shift());
182
+ return this.invoke(name, route, requestBytes, key).transform((responseBytes) => (0, serde_1.deserializeJson)(responseBytes));
183
+ };
184
+ },
185
+ });
186
+ return clientProxy;
175
187
  }
176
- sendDelayed({ path }, delayMillis) {
188
+ serviceSendClient(service, opts) {
177
189
  const clientProxy = new Proxy({}, {
178
190
  get: (_target, prop) => {
179
191
  const route = prop;
180
192
  return (...args) => {
181
- const request = (0, assumptions_1.requestFromArgs)(args);
182
- const requestBytes = dynrpc_1.RpcRequest.encode(request).finish();
183
- this.invokeOneWay(path, route, requestBytes, delayMillis);
193
+ const requestBytes = (0, serde_1.serializeJson)(args.shift());
194
+ this.invokeOneWay(service.name, route, requestBytes, opts?.delay).catch((e) => {
195
+ this.stateMachine.handleDanglingPromiseError(e);
196
+ });
184
197
  };
185
198
  },
186
199
  });
187
200
  return clientProxy;
188
201
  }
189
- // --- Methods exposed by respective interfaces to interact with other APIs
190
- grpcChannel() {
191
- return this;
202
+ objectSendClient(obj, key, opts) {
203
+ const clientProxy = new Proxy({}, {
204
+ get: (_target, prop) => {
205
+ const route = prop;
206
+ return (...args) => {
207
+ const requestBytes = (0, serde_1.serializeJson)(args.shift());
208
+ this.invokeOneWay(obj.name, route, requestBytes, opts?.delay, key).catch((e) => {
209
+ this.stateMachine.handleDanglingPromiseError(e);
210
+ });
211
+ };
212
+ },
213
+ });
214
+ return clientProxy;
192
215
  }
193
216
  // DON'T make this function async!!!
194
- // The reason is that we want the erros thrown by the initial checks to be propagated in the caller context,
217
+ // The reason is that we want the errors thrown by the initial checks to be propagated in the caller context,
195
218
  // and not in the promise context. To understand the semantic difference, make this function async and run the
196
219
  // UnawaitedSideEffectShouldFailSubsequentContextCall test.
197
- sideEffect(fn, retryPolicy = public_utils_1.DEFAULT_INFINITE_EXPONENTIAL_BACKOFF) {
198
- if (this.isInSideEffect()) {
199
- throw new errors_1.TerminalError("You cannot do sideEffect calls from within a side effect.", { errorCode: errors_1.ErrorCodes.INTERNAL });
200
- }
201
- else if (this.isInOneWayCall()) {
202
- throw new errors_1.TerminalError("Cannot do a side effect from within ctx.oneWayCall(...). " +
203
- "Context method ctx.oneWayCall() can only be used to invoke other services unidirectionally. " +
204
- "e.g. ctx.oneWayCall(() => client.greet(my_request))", { errorCode: errors_1.ErrorCodes.INTERNAL });
220
+ run(nameOrAction, actionSecondParameter) {
221
+ const { name, action } = unpack(nameOrAction, actionSecondParameter);
222
+ if (this.isInRun()) {
223
+ throw new errors_1.TerminalError("Not possible to nest runs.", {
224
+ errorCode: errors_1.INTERNAL_ERROR_CODE,
225
+ });
205
226
  }
206
- this.checkNotExecutingSideEffect();
207
- this.executingSideEffect = true;
208
- const executeAndLogSideEffect = async () => {
227
+ this.checkNotExecutingRun();
228
+ this.executingRun = true;
229
+ const executeRun = async () => {
209
230
  // in replay mode, we directly return the value from the log
210
231
  if (this.stateMachine.nextEntryWillBeReplayed()) {
211
- const emptyMsg = javascript_1.SideEffectEntryMessage.create({});
212
- return this.stateMachine.handleUserCodeMessage(protocol_2.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, emptyMsg);
232
+ const emptyMsg = new protocol_pb_1.RunEntryMessage({});
233
+ return this.stateMachine.handleUserCodeMessage(protocol_1.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, emptyMsg);
213
234
  }
214
235
  let sideEffectResult;
215
236
  try {
216
- sideEffectResult = await ContextImpl.callContext.run({ type: CallContexType.SideEffect }, fn);
237
+ sideEffectResult = await ContextImpl.callContext.run({ type: CallContextType.Run }, () => action());
217
238
  }
218
239
  catch (e) {
219
- // we commit any error from the side effet to thr journal, and re-throw it into
240
+ if (!(e instanceof errors_1.TerminalError)) {
241
+ ///non terminal errors are retirable.
242
+ // we do not commit the error itself into the journal, but rather let restate know about this
243
+ // so that restate can retry this invocation later.
244
+ // Before we can propagate this error to the user, we must let the state machine know that this attempt
245
+ // is finished with an error, and it should not append anything else to the journal from now on.
246
+ const error = (0, errors_1.ensureError)(e);
247
+ const additionalContext = {
248
+ relatedEntryName: name,
249
+ relatedEntryType: protocol_1.SIDE_EFFECT_ENTRY_MESSAGE_TYPE,
250
+ };
251
+ await this.stateMachine.sendErrorAndFinish(error, additionalContext);
252
+ throw e;
253
+ }
254
+ // we commit a terminal error from the side effect to the journal, and re-throw it into
220
255
  // the function. that way, any catching by the user and reacting to it will be
221
256
  // deterministic on replay
222
257
  const error = (0, errors_1.ensureError)(e);
223
- const failure = (0, errors_1.errorToFailureWithTerminal)(error);
224
- const sideEffectMsg = javascript_1.SideEffectEntryMessage.create({
225
- failure: failure,
258
+ const failure = (0, errors_1.errorToFailure)(error);
259
+ const sideEffectMsg = new protocol_pb_1.RunEntryMessage({
260
+ name,
261
+ result: { case: "failure", value: failure },
226
262
  });
227
263
  // this may throw an error from the SDK/runtime/connection side, in case the
228
264
  // failure message cannot be committed to the journal. That error would then
@@ -230,16 +266,22 @@ class ContextImpl {
230
266
  // that is acceptable, because in such a situation (failure to append to journal),
231
267
  // the state machine closes anyways and no further operations will succeed and the
232
268
  // the execution aborts
233
- await this.stateMachine.handleUserCodeMessage(protocol_2.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, undefined, true);
269
+ await this.stateMachine.handleUserCodeMessage(protocol_1.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, undefined, true);
234
270
  throw e;
235
271
  }
236
272
  // we have this code outside the above try/catch block, to ensure that any error arising
237
273
  // from here is not incorrectly attributed to the side-effect
238
274
  const sideEffectMsg = sideEffectResult !== undefined
239
- ? javascript_1.SideEffectEntryMessage.create({
240
- value: Buffer.from((0, utils_1.jsonSerialize)(sideEffectResult)),
275
+ ? new protocol_pb_1.RunEntryMessage({
276
+ name,
277
+ result: {
278
+ case: "value",
279
+ value: node_buffer_1.Buffer.from((0, utils_1.jsonSerialize)(sideEffectResult)),
280
+ },
241
281
  })
242
- : javascript_1.SideEffectEntryMessage.create();
282
+ : new protocol_pb_1.RunEntryMessage({
283
+ name,
284
+ });
243
285
  // if an error arises from committing the side effect result, then this error will
244
286
  // be thrown here (reject the returned promise) and the function will see that error,
245
287
  // even if the side-effect function completed correctly
@@ -250,12 +292,11 @@ class ContextImpl {
250
292
  // re-executes, and if it made it to the journal after all (error happend inly during
251
293
  // ack-back), then retries will use the journaled result.
252
294
  // So all good in any case, due to the beauty of "the runtime log is the ground thruth" approach.
253
- await this.stateMachine.handleUserCodeMessage(protocol_2.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, undefined, true);
295
+ await this.stateMachine.handleUserCodeMessage(protocol_1.SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, undefined, true);
254
296
  return sideEffectResult;
255
297
  };
256
- const sleep = (millis) => this.sleepInternal(millis);
257
- return executeWithRetries(this.console, retryPolicy, executeAndLogSideEffect, sleep).finally(() => {
258
- this.executingSideEffect = false;
298
+ return executeRun().finally(() => {
299
+ this.executingRun = false;
259
300
  });
260
301
  }
261
302
  sleep(millis) {
@@ -263,16 +304,18 @@ class ContextImpl {
263
304
  return this.markCombineablePromise(this.sleepInternal(millis));
264
305
  }
265
306
  sleepInternal(millis) {
266
- return this.stateMachine.handleUserCodeMessage(protocol_2.SLEEP_ENTRY_MESSAGE_TYPE, protocol_1.SleepEntryMessage.create({ wakeUpTime: Date.now() + millis }));
307
+ return this.stateMachine.handleUserCodeMessage(protocol_1.SLEEP_ENTRY_MESSAGE_TYPE, new protocol_pb_1.SleepEntryMessage({
308
+ wakeUpTime: protobuf_1.protoInt64.parse(Date.now() + millis),
309
+ }));
267
310
  }
268
311
  // -- Awakeables
269
312
  awakeable() {
270
313
  this.checkState("awakeable");
271
- const msg = protocol_1.AwakeableEntryMessage.create();
314
+ const msg = new protocol_pb_1.AwakeableEntryMessage();
272
315
  const promise = this.stateMachine
273
- .handleUserCodeMessage(protocol_2.AWAKEABLE_ENTRY_MESSAGE_TYPE, msg)
316
+ .handleUserCodeMessage(protocol_1.AWAKEABLE_ENTRY_MESSAGE_TYPE, msg)
274
317
  .transform((result) => {
275
- if (!(result instanceof Buffer)) {
318
+ if (!(result instanceof node_buffer_1.Buffer)) {
276
319
  // This should either be a filled buffer or an empty buffer but never anything else.
277
320
  throw errors_1.RetryableError.internal("Awakeable was not resolved with a buffer payload");
278
321
  }
@@ -280,11 +323,11 @@ class ContextImpl {
280
323
  });
281
324
  // This needs to be done after handling the message in the state machine
282
325
  // otherwise the index is not yet incremented.
283
- const encodedEntryIndex = Buffer.alloc(4 /* Size of u32 */);
326
+ const encodedEntryIndex = node_buffer_1.Buffer.alloc(4 /* Size of u32 */);
284
327
  encodedEntryIndex.writeUInt32BE(this.stateMachine.getUserCodeJournalIndex());
285
328
  return {
286
- id: protocol_2.AWAKEABLE_IDENTIFIER_PREFIX +
287
- Buffer.concat([this.id, encodedEntryIndex]).toString("base64url"),
329
+ id: protocol_1.AWAKEABLE_IDENTIFIER_PREFIX +
330
+ node_buffer_1.Buffer.concat([this.request().id, encodedEntryIndex]).toString("base64url"),
288
331
  promise: this.markCombineablePromise(promise),
289
332
  };
290
333
  }
@@ -293,24 +336,36 @@ class ContextImpl {
293
336
  const payloadToWrite = payload === undefined ? null : payload;
294
337
  this.checkState("resolveAwakeable");
295
338
  this.completeAwakeable(id, {
296
- value: Buffer.from(JSON.stringify(payloadToWrite)),
339
+ result: {
340
+ case: "value",
341
+ value: node_buffer_1.Buffer.from(JSON.stringify(payloadToWrite)),
342
+ },
297
343
  });
298
344
  }
299
345
  rejectAwakeable(id, reason) {
300
346
  this.checkState("rejectAwakeable");
301
347
  this.completeAwakeable(id, {
302
- failure: { code: errors_1.ErrorCodes.UNKNOWN, message: reason },
348
+ result: {
349
+ case: "failure",
350
+ value: { code: errors_1.UNKNOWN_ERROR_CODE, message: reason },
351
+ },
303
352
  });
304
353
  }
305
354
  completeAwakeable(id, base) {
306
355
  base.id = id;
307
- this.stateMachine.handleUserCodeMessage(protocol_2.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE, protocol_1.CompleteAwakeableEntryMessage.create(base));
356
+ this.stateMachine
357
+ .handleUserCodeMessage(protocol_1.COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE, new protocol_pb_1.CompleteAwakeableEntryMessage(base))
358
+ .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
308
359
  }
309
360
  // Used by static methods of CombineablePromise
310
- createCombinator(combinatorConstructor, promises) {
361
+ static createCombinator(combinatorConstructor, promises) {
362
+ const self = extractContext(promises[0]);
363
+ if (!self) {
364
+ throw errors_1.RetryableError.internal("Not a combinable promise");
365
+ }
311
366
  const outPromises = [];
312
367
  for (const promise of promises) {
313
- if (promise.__restate_context !== this) {
368
+ if (extractContext(promise) !== self) {
314
369
  throw errors_1.RetryableError.internal("You're mixing up CombineablePromises from different RestateContext. This is not supported.");
315
370
  }
316
371
  const index = promise
@@ -320,45 +375,32 @@ class ContextImpl {
320
375
  promise: promise,
321
376
  });
322
377
  }
323
- return this.stateMachine.createCombinator(combinatorConstructor, outPromises);
378
+ return self.stateMachine.createCombinator(combinatorConstructor, outPromises);
324
379
  }
325
380
  // -- Various private methods
326
- isInSideEffect() {
327
- const context = ContextImpl.callContext.getStore();
328
- return context?.type === CallContexType.SideEffect;
329
- }
330
- isInOneWayCall() {
331
- const context = ContextImpl.callContext.getStore();
332
- return context?.type === CallContexType.OneWayCall;
333
- }
334
- getOneWayCallDelay() {
381
+ isInRun() {
335
382
  const context = ContextImpl.callContext.getStore();
336
- return context?.delay;
383
+ return context?.type === CallContextType.Run;
337
384
  }
338
- checkNotExecutingSideEffect() {
339
- if (this.executingSideEffect) {
340
- throw new errors_1.TerminalError(`Invoked a RestateContext method while a side effect is still executing.
341
- Make sure you await the ctx.sideEffect call before using any other RestateContext method.`, { errorCode: errors_1.ErrorCodes.INTERNAL });
385
+ checkNotExecutingRun() {
386
+ if (this.executingRun) {
387
+ throw new errors_1.TerminalError(`Invoked a RestateContext method while a run() is still executing.
388
+ Make sure you await the ctx.run() call before using any other RestateContext method.`, { errorCode: errors_1.INTERNAL_ERROR_CODE });
342
389
  }
343
390
  }
344
391
  checkState(callType) {
345
392
  const context = ContextImpl.callContext.getStore();
346
393
  if (!context) {
347
- this.checkNotExecutingSideEffect();
394
+ this.checkNotExecutingRun();
348
395
  return;
349
396
  }
350
- if (context.type === CallContexType.SideEffect) {
351
- throw new errors_1.TerminalError(`You cannot do ${callType} calls from within a side effect.`, { errorCode: errors_1.ErrorCodes.INTERNAL });
352
- }
353
- if (context.type === CallContexType.OneWayCall) {
354
- throw new errors_1.TerminalError(`Cannot do a ${callType} from within ctx.oneWayCall(...).
355
- Context method oneWayCall() can only be used to invoke other services in the background.
356
- e.g. ctx.oneWayCall(() => client.greet(my_request))`, { errorCode: errors_1.ErrorCodes.INTERNAL });
397
+ if (context.type === CallContextType.Run) {
398
+ throw new errors_1.TerminalError(`You cannot do ${callType} calls from within a run.`, { errorCode: errors_1.INTERNAL_ERROR_CODE });
357
399
  }
358
400
  }
359
401
  checkStateOperation(callType) {
360
402
  if (!this.keyedContext) {
361
- throw new errors_1.TerminalError(`You can do ${callType} calls only from keyed services/routers.`, { errorCode: errors_1.ErrorCodes.INTERNAL });
403
+ throw new errors_1.TerminalError(`You can do ${callType} calls only from a virtual object`, { errorCode: errors_1.INTERNAL_ERROR_CODE });
362
404
  }
363
405
  }
364
406
  markCombineablePromise(p) {
@@ -380,7 +422,7 @@ class ContextImpl {
380
422
  ]);
381
423
  };
382
424
  return Object.defineProperties(p, {
383
- __restate_context: {
425
+ [RESTATE_CTX_SYMBOL]: {
384
426
  value: this,
385
427
  },
386
428
  journalIndex: {
@@ -393,47 +435,24 @@ class ContextImpl {
393
435
  }
394
436
  }
395
437
  exports.ContextImpl = ContextImpl;
396
- async function executeWithRetries(console, retrySettings, executeAndLogSideEffect, sleep) {
397
- const { initialDelayMs = public_utils_1.DEFAULT_INITIAL_DELAY_MS, maxDelayMs = Number.MAX_SAFE_INTEGER, maxRetries = Number.MAX_SAFE_INTEGER, policy = public_utils_1.EXPONENTIAL_BACKOFF, name = "side-effect", } = retrySettings;
398
- let currentDelayMs = initialDelayMs;
399
- let retriesLeft = maxRetries;
400
- // eslint-disable-next-line no-constant-condition
401
- while (true) {
402
- try {
403
- return await executeAndLogSideEffect();
438
+ function unpack(a, b) {
439
+ if (typeof a == "string") {
440
+ if (typeof b !== "function") {
441
+ throw new TypeError("");
404
442
  }
405
- catch (e) {
406
- if (e instanceof errors_1.TerminalError) {
407
- throw e;
408
- }
409
- // journal mismatch errors are special:
410
- // - they are not terminal errors, because we want to allow pushing new code so
411
- // that retries succeed later
412
- // - they are not retried within the service, because they will never succeed within this service,
413
- // but can only succeed within a new invocation going to service with fixed code
414
- // we hence break the retries here similar to terminal errors
415
- if (e instanceof errors_1.RestateError &&
416
- e.code == errors_1.RestateErrorCodes.JOURNAL_MISMATCH) {
417
- throw e;
418
- }
419
- const error = (0, errors_1.ensureError)(e);
420
- console.debug("Error while executing side effect '%s': %s - %s", name, error.name, error.message);
421
- if (error.stack) {
422
- console.debug(error.stack);
423
- }
424
- if (retriesLeft > 0) {
425
- console.debug("Retrying in %d ms", currentDelayMs);
426
- }
427
- else {
428
- console.debug("No retries left.");
429
- throw new errors_1.TerminalError(`Retries exhausted for ${name}. Last error: ${error.name}: ${error.message}`, {
430
- errorCode: errors_1.ErrorCodes.INTERNAL,
431
- });
432
- }
433
- }
434
- await sleep(currentDelayMs);
435
- retriesLeft -= 1;
436
- currentDelayMs = Math.min(policy.computeNextDelay(currentDelayMs), maxDelayMs);
443
+ return { name: a, action: b };
437
444
  }
445
+ if (typeof a !== "function") {
446
+ throw new TypeError("unexpected type at the first parameter");
447
+ }
448
+ if (b) {
449
+ throw new TypeError("unexpected a function as a second parameter.");
450
+ }
451
+ return { action: a };
452
+ }
453
+ const RESTATE_CTX_SYMBOL = Symbol("restateContext");
454
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
455
+ function extractContext(n) {
456
+ return n[RESTATE_CTX_SYMBOL];
438
457
  }
439
458
  //# sourceMappingURL=context_impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context_impl.js","sourceRoot":"","sources":["../../src/context_impl.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAYH,+DAWuC;AACvC,+CAa0B;AAC1B,uDAAqD;AACrD,2CAQwB;AACxB,yCAA+D;AAC/D,iDAAgE;AAEhE,uCAAwC;AACxC,6EAAwE;AAExE,6CAAqC;AACrC,yCAA+D;AAE/D,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,qDAAI,CAAA;IACJ,mDAAG,CAAA;AACL,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B;AAYD,MAAa,WAAW;IA0BJ;IACA;IACA;IAIC;IACD;IAhClB,mFAAmF;IACnF,6CAA6C;IAC7C,2CAA2C;IAC3C,mFAAmF;IACnF,8EAA8E;IAC9E,oFAAoF;IACpF,MAAM,CAAC,WAAW,GAAG,IAAI,oCAAiB,EAAe,CAAC;IAE1D,kFAAkF;IAClF,gFAAgF;IACxE,YAAY,GAAG,KAAK,CAAC;IACZ,iBAAiB,CAAU;IAE5B,IAAI,GAAgB;QAClC,GAAG,EAAE,GAAoB,EAAE;YACzB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,EAAE,GAAoB,EAAE;YAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;IAEF,YACE,EAAU,EACM,OAAgB,EAChB,YAAqB,EACrB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