@restatedev/restate-sdk 1.3.3 → 1.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 (416) hide show
  1. package/README.md +4 -4
  2. package/dist/cjs/src/context.d.ts +35 -2
  3. package/dist/cjs/src/context.d.ts.map +1 -1
  4. package/dist/cjs/src/context.js +8 -8
  5. package/dist/cjs/src/context.js.map +1 -1
  6. package/dist/cjs/src/context_impl.d.ts +61 -17
  7. package/dist/cjs/src/context_impl.d.ts.map +1 -1
  8. package/dist/cjs/src/context_impl.js +529 -316
  9. package/dist/cjs/src/context_impl.js.map +1 -1
  10. package/dist/cjs/src/endpoint/endpoint_builder.d.ts +2 -3
  11. package/dist/cjs/src/endpoint/endpoint_builder.d.ts.map +1 -1
  12. package/dist/cjs/src/endpoint/endpoint_builder.js +4 -9
  13. package/dist/cjs/src/endpoint/endpoint_builder.js.map +1 -1
  14. package/dist/cjs/src/endpoint/fetch_endpoint.d.ts +1 -2
  15. package/dist/cjs/src/endpoint/fetch_endpoint.d.ts.map +1 -1
  16. package/dist/cjs/src/endpoint/fetch_endpoint.js.map +1 -1
  17. package/dist/cjs/src/endpoint/handlers/generic.d.ts +15 -0
  18. package/dist/cjs/src/endpoint/handlers/generic.d.ts.map +1 -1
  19. package/dist/cjs/src/endpoint/handlers/generic.js +185 -83
  20. package/dist/cjs/src/endpoint/handlers/generic.js.map +1 -1
  21. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +300 -0
  22. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +1 -0
  23. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +1646 -0
  24. package/dist/cjs/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -0
  25. package/dist/cjs/src/endpoint/lambda_endpoint.d.ts +1 -2
  26. package/dist/cjs/src/endpoint/lambda_endpoint.d.ts.map +1 -1
  27. package/dist/cjs/src/endpoint/lambda_endpoint.js.map +1 -1
  28. package/dist/cjs/src/endpoint/node_endpoint.d.ts +1 -2
  29. package/dist/cjs/src/endpoint/node_endpoint.d.ts.map +1 -1
  30. package/dist/cjs/src/endpoint/node_endpoint.js.map +1 -1
  31. package/dist/cjs/src/generated/version.d.ts +1 -1
  32. package/dist/cjs/src/generated/version.js +1 -1
  33. package/dist/cjs/src/logger.js +1 -1
  34. package/dist/cjs/src/logger.js.map +1 -1
  35. package/dist/cjs/src/types/components.js +2 -2
  36. package/dist/cjs/src/types/components.js.map +1 -1
  37. package/dist/cjs/src/types/errors.d.ts +1 -32
  38. package/dist/cjs/src/types/errors.d.ts.map +1 -1
  39. package/dist/cjs/src/types/errors.js +9 -76
  40. package/dist/cjs/src/types/errors.js.map +1 -1
  41. package/dist/cjs/src/types/rpc.js +9 -9
  42. package/dist/cjs/src/types/rpc.js.map +1 -1
  43. package/dist/cjs/src/user_agent.d.ts +1 -1
  44. package/dist/cjs/src/utils/completable_promise.d.ts +9 -0
  45. package/dist/cjs/src/utils/completable_promise.d.ts.map +1 -0
  46. package/dist/cjs/src/utils/completable_promise.js +34 -0
  47. package/dist/cjs/src/utils/completable_promise.js.map +1 -0
  48. package/dist/cjs/src/utils/rand.d.ts +1 -1
  49. package/dist/cjs/src/utils/rand.d.ts.map +1 -1
  50. package/dist/cjs/src/utils/rand.js +1 -1
  51. package/dist/cjs/src/utils/rand.js.map +1 -1
  52. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  53. package/dist/esm/src/context.d.ts +35 -2
  54. package/dist/esm/src/context.d.ts.map +1 -1
  55. package/dist/esm/src/context.js +8 -8
  56. package/dist/esm/src/context.js.map +1 -1
  57. package/dist/esm/src/context_impl.d.ts +61 -17
  58. package/dist/esm/src/context_impl.d.ts.map +1 -1
  59. package/dist/esm/src/context_impl.js +531 -318
  60. package/dist/esm/src/context_impl.js.map +1 -1
  61. package/dist/esm/src/endpoint/endpoint_builder.d.ts +2 -3
  62. package/dist/esm/src/endpoint/endpoint_builder.d.ts.map +1 -1
  63. package/dist/esm/src/endpoint/endpoint_builder.js +4 -9
  64. package/dist/esm/src/endpoint/endpoint_builder.js.map +1 -1
  65. package/dist/esm/src/endpoint/fetch_endpoint.d.ts +1 -2
  66. package/dist/esm/src/endpoint/fetch_endpoint.d.ts.map +1 -1
  67. package/dist/esm/src/endpoint/fetch_endpoint.js.map +1 -1
  68. package/dist/esm/src/endpoint/handlers/generic.d.ts +15 -0
  69. package/dist/esm/src/endpoint/handlers/generic.d.ts.map +1 -1
  70. package/dist/esm/src/endpoint/handlers/generic.js +162 -84
  71. package/dist/esm/src/endpoint/handlers/generic.js.map +1 -1
  72. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +300 -0
  73. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.d.ts.map +1 -0
  74. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js +1636 -0
  75. package/dist/esm/src/endpoint/handlers/vm/sdk_shared_core_wasm_bindings.js.map +1 -0
  76. package/dist/esm/src/endpoint/lambda_endpoint.d.ts +1 -2
  77. package/dist/esm/src/endpoint/lambda_endpoint.d.ts.map +1 -1
  78. package/dist/esm/src/endpoint/lambda_endpoint.js.map +1 -1
  79. package/dist/esm/src/endpoint/node_endpoint.d.ts +1 -2
  80. package/dist/esm/src/endpoint/node_endpoint.d.ts.map +1 -1
  81. package/dist/esm/src/endpoint/node_endpoint.js.map +1 -1
  82. package/dist/esm/src/generated/version.d.ts +1 -1
  83. package/dist/esm/src/generated/version.js +1 -1
  84. package/dist/esm/src/logger.js +1 -1
  85. package/dist/esm/src/logger.js.map +1 -1
  86. package/dist/esm/src/types/components.js +2 -2
  87. package/dist/esm/src/types/components.js.map +1 -1
  88. package/dist/esm/src/types/errors.d.ts +1 -32
  89. package/dist/esm/src/types/errors.d.ts.map +1 -1
  90. package/dist/esm/src/types/errors.js +8 -70
  91. package/dist/esm/src/types/errors.js.map +1 -1
  92. package/dist/esm/src/types/rpc.js +9 -9
  93. package/dist/esm/src/types/rpc.js.map +1 -1
  94. package/dist/esm/src/user_agent.d.ts +1 -1
  95. package/dist/esm/src/utils/completable_promise.d.ts +9 -0
  96. package/dist/esm/src/utils/completable_promise.d.ts.map +1 -0
  97. package/dist/esm/src/utils/completable_promise.js +30 -0
  98. package/dist/esm/src/utils/completable_promise.js.map +1 -0
  99. package/dist/esm/src/utils/rand.d.ts +1 -1
  100. package/dist/esm/src/utils/rand.d.ts.map +1 -1
  101. package/dist/esm/src/utils/rand.js +1 -1
  102. package/dist/esm/src/utils/rand.js.map +1 -1
  103. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  104. package/package.json +2 -6
  105. package/dist/cjs/src/connection/connection.d.ts +0 -84
  106. package/dist/cjs/src/connection/connection.d.ts.map +0 -1
  107. package/dist/cjs/src/connection/connection.js +0 -181
  108. package/dist/cjs/src/connection/connection.js.map +0 -1
  109. package/dist/cjs/src/endpoint/request_signing/basex.d.ts +0 -10
  110. package/dist/cjs/src/endpoint/request_signing/basex.d.ts.map +0 -1
  111. package/dist/cjs/src/endpoint/request_signing/basex.js +0 -138
  112. package/dist/cjs/src/endpoint/request_signing/basex.js.map +0 -1
  113. package/dist/cjs/src/endpoint/request_signing/ed25519.d.ts +0 -17
  114. package/dist/cjs/src/endpoint/request_signing/ed25519.d.ts.map +0 -1
  115. package/dist/cjs/src/endpoint/request_signing/ed25519.js +0 -80
  116. package/dist/cjs/src/endpoint/request_signing/ed25519.js.map +0 -1
  117. package/dist/cjs/src/endpoint/request_signing/v1.d.ts +0 -10
  118. package/dist/cjs/src/endpoint/request_signing/v1.d.ts.map +0 -1
  119. package/dist/cjs/src/endpoint/request_signing/v1.js +0 -151
  120. package/dist/cjs/src/endpoint/request_signing/v1.js.map +0 -1
  121. package/dist/cjs/src/endpoint/request_signing/validate.d.ts +0 -19
  122. package/dist/cjs/src/endpoint/request_signing/validate.d.ts.map +0 -1
  123. package/dist/cjs/src/endpoint/request_signing/validate.js +0 -45
  124. package/dist/cjs/src/endpoint/request_signing/validate.js.map +0 -1
  125. package/dist/cjs/src/generated/proto/discovery_pb.d.ts +0 -18
  126. package/dist/cjs/src/generated/proto/discovery_pb.d.ts.map +0 -1
  127. package/dist/cjs/src/generated/proto/discovery_pb.js +0 -40
  128. package/dist/cjs/src/generated/proto/discovery_pb.js.map +0 -1
  129. package/dist/cjs/src/generated/proto/javascript_pb.d.ts +0 -26
  130. package/dist/cjs/src/generated/proto/javascript_pb.d.ts.map +0 -1
  131. package/dist/cjs/src/generated/proto/javascript_pb.js +0 -52
  132. package/dist/cjs/src/generated/proto/javascript_pb.js.map +0 -1
  133. package/dist/cjs/src/generated/proto/protocol_pb.d.ts +0 -1051
  134. package/dist/cjs/src/generated/proto/protocol_pb.d.ts.map +0 -1
  135. package/dist/cjs/src/generated/proto/protocol_pb.js +0 -1288
  136. package/dist/cjs/src/generated/proto/protocol_pb.js.map +0 -1
  137. package/dist/cjs/src/invocation.d.ts +0 -48
  138. package/dist/cjs/src/invocation.d.ts.map +0 -1
  139. package/dist/cjs/src/invocation.js +0 -158
  140. package/dist/cjs/src/invocation.js.map +0 -1
  141. package/dist/cjs/src/io/decoder.d.ts +0 -9
  142. package/dist/cjs/src/io/decoder.d.ts.map +0 -1
  143. package/dist/cjs/src/io/decoder.js +0 -137
  144. package/dist/cjs/src/io/decoder.js.map +0 -1
  145. package/dist/cjs/src/io/encoder.d.ts +0 -4
  146. package/dist/cjs/src/io/encoder.d.ts.map +0 -1
  147. package/dist/cjs/src/io/encoder.js +0 -41
  148. package/dist/cjs/src/io/encoder.js.map +0 -1
  149. package/dist/cjs/src/journal.d.ts +0 -52
  150. package/dist/cjs/src/journal.d.ts.map +0 -1
  151. package/dist/cjs/src/journal.js +0 -438
  152. package/dist/cjs/src/journal.js.map +0 -1
  153. package/dist/cjs/src/local_state_store.d.ts +0 -14
  154. package/dist/cjs/src/local_state_store.d.ts.map +0 -1
  155. package/dist/cjs/src/local_state_store.js +0 -83
  156. package/dist/cjs/src/local_state_store.js.map +0 -1
  157. package/dist/cjs/src/promise_combinator_tracker.d.ts +0 -29
  158. package/dist/cjs/src/promise_combinator_tracker.d.ts.map +0 -1
  159. package/dist/cjs/src/promise_combinator_tracker.js +0 -130
  160. package/dist/cjs/src/promise_combinator_tracker.js.map +0 -1
  161. package/dist/cjs/src/state_machine.d.ts +0 -85
  162. package/dist/cjs/src/state_machine.d.ts.map +0 -1
  163. package/dist/cjs/src/state_machine.js +0 -426
  164. package/dist/cjs/src/state_machine.js.map +0 -1
  165. package/dist/cjs/src/types/protocol.d.ts +0 -40
  166. package/dist/cjs/src/types/protocol.d.ts.map +0 -1
  167. package/dist/cjs/src/types/protocol.js +0 -237
  168. package/dist/cjs/src/types/protocol.js.map +0 -1
  169. package/dist/cjs/src/types/types.d.ts +0 -20
  170. package/dist/cjs/src/types/types.d.ts.map +0 -1
  171. package/dist/cjs/src/types/types.js +0 -110
  172. package/dist/cjs/src/types/types.js.map +0 -1
  173. package/dist/cjs/src/utils/message_logger.d.ts +0 -7
  174. package/dist/cjs/src/utils/message_logger.d.ts.map +0 -1
  175. package/dist/cjs/src/utils/message_logger.js +0 -79
  176. package/dist/cjs/src/utils/message_logger.js.map +0 -1
  177. package/dist/cjs/src/utils/promises.d.ts +0 -15
  178. package/dist/cjs/src/utils/promises.d.ts.map +0 -1
  179. package/dist/cjs/src/utils/promises.js +0 -68
  180. package/dist/cjs/src/utils/promises.js.map +0 -1
  181. package/dist/cjs/src/utils/utils.d.ts +0 -3
  182. package/dist/cjs/src/utils/utils.d.ts.map +0 -1
  183. package/dist/cjs/src/utils/utils.js +0 -105
  184. package/dist/cjs/src/utils/utils.js.map +0 -1
  185. package/dist/cjs/test/awakeable.test.d.ts +0 -2
  186. package/dist/cjs/test/awakeable.test.d.ts.map +0 -1
  187. package/dist/cjs/test/awakeable.test.js +0 -141
  188. package/dist/cjs/test/awakeable.test.js.map +0 -1
  189. package/dist/cjs/test/complete_awakeable.test.d.ts +0 -2
  190. package/dist/cjs/test/complete_awakeable.test.d.ts.map +0 -1
  191. package/dist/cjs/test/complete_awakeable.test.js +0 -123
  192. package/dist/cjs/test/complete_awakeable.test.js.map +0 -1
  193. package/dist/cjs/test/eager_state.test.d.ts +0 -2
  194. package/dist/cjs/test/eager_state.test.d.ts.map +0 -1
  195. package/dist/cjs/test/eager_state.test.js +0 -280
  196. package/dist/cjs/test/eager_state.test.js.map +0 -1
  197. package/dist/cjs/test/get_and_set_state.test.d.ts +0 -2
  198. package/dist/cjs/test/get_and_set_state.test.d.ts.map +0 -1
  199. package/dist/cjs/test/get_and_set_state.test.js +0 -233
  200. package/dist/cjs/test/get_and_set_state.test.js.map +0 -1
  201. package/dist/cjs/test/get_state.test.d.ts +0 -2
  202. package/dist/cjs/test/get_state.test.d.ts.map +0 -1
  203. package/dist/cjs/test/get_state.test.js +0 -328
  204. package/dist/cjs/test/get_state.test.js.map +0 -1
  205. package/dist/cjs/test/lambda.test.d.ts +0 -2
  206. package/dist/cjs/test/lambda.test.d.ts.map +0 -1
  207. package/dist/cjs/test/lambda.test.js +0 -258
  208. package/dist/cjs/test/lambda.test.js.map +0 -1
  209. package/dist/cjs/test/message_coders.test.d.ts +0 -2
  210. package/dist/cjs/test/message_coders.test.d.ts.map +0 -1
  211. package/dist/cjs/test/message_coders.test.js +0 -37
  212. package/dist/cjs/test/message_coders.test.js.map +0 -1
  213. package/dist/cjs/test/promise_combinator_tracker.test.d.ts +0 -2
  214. package/dist/cjs/test/promise_combinator_tracker.test.d.ts.map +0 -1
  215. package/dist/cjs/test/promise_combinator_tracker.test.js +0 -156
  216. package/dist/cjs/test/promise_combinator_tracker.test.js.map +0 -1
  217. package/dist/cjs/test/promise_combinators.test.d.ts +0 -2
  218. package/dist/cjs/test/promise_combinators.test.d.ts.map +0 -1
  219. package/dist/cjs/test/promise_combinators.test.js +0 -433
  220. package/dist/cjs/test/promise_combinators.test.js.map +0 -1
  221. package/dist/cjs/test/promises.test.d.ts +0 -2
  222. package/dist/cjs/test/promises.test.d.ts.map +0 -1
  223. package/dist/cjs/test/promises.test.js +0 -32
  224. package/dist/cjs/test/promises.test.js.map +0 -1
  225. package/dist/cjs/test/protocol_stream.test.d.ts +0 -2
  226. package/dist/cjs/test/protocol_stream.test.d.ts.map +0 -1
  227. package/dist/cjs/test/protocol_stream.test.js +0 -243
  228. package/dist/cjs/test/protocol_stream.test.js.map +0 -1
  229. package/dist/cjs/test/protoutils.d.ts +0 -44
  230. package/dist/cjs/test/protoutils.d.ts.map +0 -1
  231. package/dist/cjs/test/protoutils.js +0 -368
  232. package/dist/cjs/test/protoutils.js.map +0 -1
  233. package/dist/cjs/test/service_bind.test.d.ts +0 -2
  234. package/dist/cjs/test/service_bind.test.d.ts.map +0 -1
  235. package/dist/cjs/test/service_bind.test.js +0 -118
  236. package/dist/cjs/test/service_bind.test.js.map +0 -1
  237. package/dist/cjs/test/side_effect.test.d.ts +0 -2
  238. package/dist/cjs/test/side_effect.test.d.ts.map +0 -1
  239. package/dist/cjs/test/side_effect.test.js +0 -133
  240. package/dist/cjs/test/side_effect.test.js.map +0 -1
  241. package/dist/cjs/test/sleep.test.d.ts +0 -2
  242. package/dist/cjs/test/sleep.test.d.ts.map +0 -1
  243. package/dist/cjs/test/sleep.test.js +0 -224
  244. package/dist/cjs/test/sleep.test.js.map +0 -1
  245. package/dist/cjs/test/state_keys.test.d.ts +0 -2
  246. package/dist/cjs/test/state_keys.test.d.ts.map +0 -1
  247. package/dist/cjs/test/state_keys.test.js +0 -92
  248. package/dist/cjs/test/state_keys.test.js.map +0 -1
  249. package/dist/cjs/test/state_machine.test.d.ts +0 -2
  250. package/dist/cjs/test/state_machine.test.d.ts.map +0 -1
  251. package/dist/cjs/test/state_machine.test.js +0 -42
  252. package/dist/cjs/test/state_machine.test.js.map +0 -1
  253. package/dist/cjs/test/testdriver.d.ts +0 -39
  254. package/dist/cjs/test/testdriver.d.ts.map +0 -1
  255. package/dist/cjs/test/testdriver.js +0 -188
  256. package/dist/cjs/test/testdriver.js.map +0 -1
  257. package/dist/cjs/test/utils.test.d.ts +0 -2
  258. package/dist/cjs/test/utils.test.d.ts.map +0 -1
  259. package/dist/cjs/test/utils.test.js +0 -93
  260. package/dist/cjs/test/utils.test.js.map +0 -1
  261. package/dist/esm/src/connection/connection.d.ts +0 -84
  262. package/dist/esm/src/connection/connection.d.ts.map +0 -1
  263. package/dist/esm/src/connection/connection.js +0 -177
  264. package/dist/esm/src/connection/connection.js.map +0 -1
  265. package/dist/esm/src/endpoint/request_signing/basex.d.ts +0 -10
  266. package/dist/esm/src/endpoint/request_signing/basex.d.ts.map +0 -1
  267. package/dist/esm/src/endpoint/request_signing/basex.js +0 -136
  268. package/dist/esm/src/endpoint/request_signing/basex.js.map +0 -1
  269. package/dist/esm/src/endpoint/request_signing/ed25519.d.ts +0 -17
  270. package/dist/esm/src/endpoint/request_signing/ed25519.d.ts.map +0 -1
  271. package/dist/esm/src/endpoint/request_signing/ed25519.js +0 -52
  272. package/dist/esm/src/endpoint/request_signing/ed25519.js.map +0 -1
  273. package/dist/esm/src/endpoint/request_signing/v1.d.ts +0 -10
  274. package/dist/esm/src/endpoint/request_signing/v1.d.ts.map +0 -1
  275. package/dist/esm/src/endpoint/request_signing/v1.js +0 -143
  276. package/dist/esm/src/endpoint/request_signing/v1.js.map +0 -1
  277. package/dist/esm/src/endpoint/request_signing/validate.d.ts +0 -19
  278. package/dist/esm/src/endpoint/request_signing/validate.d.ts.map +0 -1
  279. package/dist/esm/src/endpoint/request_signing/validate.js +0 -40
  280. package/dist/esm/src/endpoint/request_signing/validate.js.map +0 -1
  281. package/dist/esm/src/generated/proto/discovery_pb.d.ts +0 -18
  282. package/dist/esm/src/generated/proto/discovery_pb.d.ts.map +0 -1
  283. package/dist/esm/src/generated/proto/discovery_pb.js +0 -37
  284. package/dist/esm/src/generated/proto/discovery_pb.js.map +0 -1
  285. package/dist/esm/src/generated/proto/javascript_pb.d.ts +0 -26
  286. package/dist/esm/src/generated/proto/javascript_pb.d.ts.map +0 -1
  287. package/dist/esm/src/generated/proto/javascript_pb.js +0 -48
  288. package/dist/esm/src/generated/proto/javascript_pb.js.map +0 -1
  289. package/dist/esm/src/generated/proto/protocol_pb.d.ts +0 -1051
  290. package/dist/esm/src/generated/proto/protocol_pb.d.ts.map +0 -1
  291. package/dist/esm/src/generated/proto/protocol_pb.js +0 -1258
  292. package/dist/esm/src/generated/proto/protocol_pb.js.map +0 -1
  293. package/dist/esm/src/invocation.d.ts +0 -48
  294. package/dist/esm/src/invocation.d.ts.map +0 -1
  295. package/dist/esm/src/invocation.js +0 -153
  296. package/dist/esm/src/invocation.js.map +0 -1
  297. package/dist/esm/src/io/decoder.d.ts +0 -9
  298. package/dist/esm/src/io/decoder.d.ts.map +0 -1
  299. package/dist/esm/src/io/decoder.js +0 -128
  300. package/dist/esm/src/io/decoder.js.map +0 -1
  301. package/dist/esm/src/io/encoder.d.ts +0 -4
  302. package/dist/esm/src/io/encoder.d.ts.map +0 -1
  303. package/dist/esm/src/io/encoder.js +0 -36
  304. package/dist/esm/src/io/encoder.js.map +0 -1
  305. package/dist/esm/src/journal.d.ts +0 -52
  306. package/dist/esm/src/journal.d.ts.map +0 -1
  307. package/dist/esm/src/journal.js +0 -410
  308. package/dist/esm/src/journal.js.map +0 -1
  309. package/dist/esm/src/local_state_store.d.ts +0 -14
  310. package/dist/esm/src/local_state_store.d.ts.map +0 -1
  311. package/dist/esm/src/local_state_store.js +0 -79
  312. package/dist/esm/src/local_state_store.js.map +0 -1
  313. package/dist/esm/src/promise_combinator_tracker.d.ts +0 -29
  314. package/dist/esm/src/promise_combinator_tracker.d.ts.map +0 -1
  315. package/dist/esm/src/promise_combinator_tracker.js +0 -125
  316. package/dist/esm/src/promise_combinator_tracker.js.map +0 -1
  317. package/dist/esm/src/state_machine.d.ts +0 -85
  318. package/dist/esm/src/state_machine.d.ts.map +0 -1
  319. package/dist/esm/src/state_machine.js +0 -399
  320. package/dist/esm/src/state_machine.js.map +0 -1
  321. package/dist/esm/src/types/protocol.d.ts +0 -40
  322. package/dist/esm/src/types/protocol.d.ts.map +0 -1
  323. package/dist/esm/src/types/protocol.js +0 -206
  324. package/dist/esm/src/types/protocol.js.map +0 -1
  325. package/dist/esm/src/types/types.d.ts +0 -20
  326. package/dist/esm/src/types/types.d.ts.map +0 -1
  327. package/dist/esm/src/types/types.js +0 -105
  328. package/dist/esm/src/types/types.js.map +0 -1
  329. package/dist/esm/src/utils/message_logger.d.ts +0 -7
  330. package/dist/esm/src/utils/message_logger.d.ts.map +0 -1
  331. package/dist/esm/src/utils/message_logger.js +0 -75
  332. package/dist/esm/src/utils/message_logger.js.map +0 -1
  333. package/dist/esm/src/utils/promises.d.ts +0 -15
  334. package/dist/esm/src/utils/promises.d.ts.map +0 -1
  335. package/dist/esm/src/utils/promises.js +0 -63
  336. package/dist/esm/src/utils/promises.js.map +0 -1
  337. package/dist/esm/src/utils/utils.d.ts +0 -3
  338. package/dist/esm/src/utils/utils.d.ts.map +0 -1
  339. package/dist/esm/src/utils/utils.js +0 -101
  340. package/dist/esm/src/utils/utils.js.map +0 -1
  341. package/dist/esm/test/awakeable.test.d.ts +0 -2
  342. package/dist/esm/test/awakeable.test.d.ts.map +0 -1
  343. package/dist/esm/test/awakeable.test.js +0 -139
  344. package/dist/esm/test/awakeable.test.js.map +0 -1
  345. package/dist/esm/test/complete_awakeable.test.d.ts +0 -2
  346. package/dist/esm/test/complete_awakeable.test.d.ts.map +0 -1
  347. package/dist/esm/test/complete_awakeable.test.js +0 -121
  348. package/dist/esm/test/complete_awakeable.test.js.map +0 -1
  349. package/dist/esm/test/eager_state.test.d.ts +0 -2
  350. package/dist/esm/test/eager_state.test.d.ts.map +0 -1
  351. package/dist/esm/test/eager_state.test.js +0 -278
  352. package/dist/esm/test/eager_state.test.js.map +0 -1
  353. package/dist/esm/test/get_and_set_state.test.d.ts +0 -2
  354. package/dist/esm/test/get_and_set_state.test.d.ts.map +0 -1
  355. package/dist/esm/test/get_and_set_state.test.js +0 -231
  356. package/dist/esm/test/get_and_set_state.test.js.map +0 -1
  357. package/dist/esm/test/get_state.test.d.ts +0 -2
  358. package/dist/esm/test/get_state.test.d.ts.map +0 -1
  359. package/dist/esm/test/get_state.test.js +0 -326
  360. package/dist/esm/test/get_state.test.js.map +0 -1
  361. package/dist/esm/test/lambda.test.d.ts +0 -2
  362. package/dist/esm/test/lambda.test.d.ts.map +0 -1
  363. package/dist/esm/test/lambda.test.js +0 -233
  364. package/dist/esm/test/lambda.test.js.map +0 -1
  365. package/dist/esm/test/message_coders.test.d.ts +0 -2
  366. package/dist/esm/test/message_coders.test.d.ts.map +0 -1
  367. package/dist/esm/test/message_coders.test.js +0 -35
  368. package/dist/esm/test/message_coders.test.js.map +0 -1
  369. package/dist/esm/test/promise_combinator_tracker.test.d.ts +0 -2
  370. package/dist/esm/test/promise_combinator_tracker.test.d.ts.map +0 -1
  371. package/dist/esm/test/promise_combinator_tracker.test.js +0 -154
  372. package/dist/esm/test/promise_combinator_tracker.test.js.map +0 -1
  373. package/dist/esm/test/promise_combinators.test.d.ts +0 -2
  374. package/dist/esm/test/promise_combinators.test.d.ts.map +0 -1
  375. package/dist/esm/test/promise_combinators.test.js +0 -431
  376. package/dist/esm/test/promise_combinators.test.js.map +0 -1
  377. package/dist/esm/test/promises.test.d.ts +0 -2
  378. package/dist/esm/test/promises.test.d.ts.map +0 -1
  379. package/dist/esm/test/promises.test.js +0 -30
  380. package/dist/esm/test/promises.test.js.map +0 -1
  381. package/dist/esm/test/protocol_stream.test.d.ts +0 -2
  382. package/dist/esm/test/protocol_stream.test.d.ts.map +0 -1
  383. package/dist/esm/test/protocol_stream.test.js +0 -218
  384. package/dist/esm/test/protocol_stream.test.js.map +0 -1
  385. package/dist/esm/test/protoutils.d.ts +0 -44
  386. package/dist/esm/test/protoutils.d.ts.map +0 -1
  387. package/dist/esm/test/protoutils.js +0 -335
  388. package/dist/esm/test/protoutils.js.map +0 -1
  389. package/dist/esm/test/service_bind.test.d.ts +0 -2
  390. package/dist/esm/test/service_bind.test.d.ts.map +0 -1
  391. package/dist/esm/test/service_bind.test.js +0 -93
  392. package/dist/esm/test/service_bind.test.js.map +0 -1
  393. package/dist/esm/test/side_effect.test.d.ts +0 -2
  394. package/dist/esm/test/side_effect.test.d.ts.map +0 -1
  395. package/dist/esm/test/side_effect.test.js +0 -131
  396. package/dist/esm/test/side_effect.test.js.map +0 -1
  397. package/dist/esm/test/sleep.test.d.ts +0 -2
  398. package/dist/esm/test/sleep.test.d.ts.map +0 -1
  399. package/dist/esm/test/sleep.test.js +0 -222
  400. package/dist/esm/test/sleep.test.js.map +0 -1
  401. package/dist/esm/test/state_keys.test.d.ts +0 -2
  402. package/dist/esm/test/state_keys.test.d.ts.map +0 -1
  403. package/dist/esm/test/state_keys.test.js +0 -90
  404. package/dist/esm/test/state_keys.test.js.map +0 -1
  405. package/dist/esm/test/state_machine.test.d.ts +0 -2
  406. package/dist/esm/test/state_machine.test.d.ts.map +0 -1
  407. package/dist/esm/test/state_machine.test.js +0 -40
  408. package/dist/esm/test/state_machine.test.js.map +0 -1
  409. package/dist/esm/test/testdriver.d.ts +0 -39
  410. package/dist/esm/test/testdriver.d.ts.map +0 -1
  411. package/dist/esm/test/testdriver.js +0 -182
  412. package/dist/esm/test/testdriver.js.map +0 -1
  413. package/dist/esm/test/utils.test.d.ts +0 -2
  414. package/dist/esm/test/utils.test.d.ts.map +0 -1
  415. package/dist/esm/test/utils.test.js +0 -91
  416. package/dist/esm/test/utils.test.js.map +0 -1
@@ -8,23 +8,18 @@
8
8
  * directory of this repository or package, or at
9
9
  * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
10
10
  */
11
- import { AwakeableEntryMessage, OneWayCallEntryMessage, CompleteAwakeableEntryMessage, Empty, GetStateEntryMessage, GetStateKeysEntryMessage, CallEntryMessage, RunEntryMessage, SleepEntryMessage, GetPromiseEntryMessage, PeekPromiseEntryMessage, CompletePromiseEntryMessage, } from "./generated/proto/protocol_pb.js";
12
- import { AWAKEABLE_ENTRY_MESSAGE_TYPE, AWAKEABLE_IDENTIFIER_PREFIX, BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE, CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE, CLEAR_STATE_ENTRY_MESSAGE_TYPE, COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE, GET_STATE_ENTRY_MESSAGE_TYPE, GET_STATE_KEYS_ENTRY_MESSAGE_TYPE, INVOKE_ENTRY_MESSAGE_TYPE, SET_STATE_ENTRY_MESSAGE_TYPE, SIDE_EFFECT_ENTRY_MESSAGE_TYPE, SLEEP_ENTRY_MESSAGE_TYPE, GET_PROMISE_MESSAGE_TYPE, PEEK_PROMISE_MESSAGE_TYPE, COMPLETE_PROMISE_MESSAGE_TYPE, } from "./types/protocol.js";
13
- import { RetryableError, TerminalError, ensureError, TimeoutError, INTERNAL_ERROR_CODE, UNKNOWN_ERROR_CODE, errorToFailure, } from "./types/errors.js";
14
- import { protoInt64 } from "@bufbuild/protobuf";
15
- import { HandlerKind, makeRpcCallProxy, makeRpcSendProxy, defaultSerde, } from "./types/rpc.js";
11
+ import { ensureError, INTERNAL_ERROR_CODE, RestateError, SUSPENDED_ERROR_CODE, TerminalError, TimeoutError, UNKNOWN_ERROR_CODE, } from "./types/errors.js";
12
+ import { defaultSerde, HandlerKind, makeRpcCallProxy, makeRpcSendProxy, } from "./types/rpc.js";
16
13
  import { serde } from "@restatedev/restate-sdk-core";
17
14
  import { RandImpl } from "./utils/rand.js";
18
- import { newJournalEntryPromiseId } from "./promise_combinator_tracker.js";
19
- import { Buffer } from "node:buffer";
20
15
  export class ContextImpl {
16
+ coreVm;
17
+ input;
21
18
  console;
22
19
  handlerKind;
23
- keyedContextKey;
24
- stateMachine;
25
- // This is used to guard users against calling ctx.sideEffect without awaiting it.
26
- // See https://github.com/restatedev/sdk-typescript/issues/197 for more details.
27
- executingRun = false;
20
+ invocationEndPromise;
21
+ inputReader;
22
+ outputWriter;
28
23
  invocationRequest;
29
24
  rand;
30
25
  date = {
@@ -35,137 +30,122 @@ export class ContextImpl {
35
30
  return this.run(() => new Date().toJSON());
36
31
  },
37
32
  };
38
- constructor(id, console, handlerKind, keyedContextKey, invocationValue, invocationHeaders, attemptHeaders, extraArgs,
39
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
- stateMachine) {
33
+ currentRead;
34
+ constructor(coreVm, input, console, handlerKind, attemptHeaders, extraArgs, invocationEndPromise, inputReader, outputWriter) {
35
+ this.coreVm = coreVm;
36
+ this.input = input;
41
37
  this.console = console;
42
38
  this.handlerKind = handlerKind;
43
- this.keyedContextKey = keyedContextKey;
44
- this.stateMachine = stateMachine;
39
+ this.invocationEndPromise = invocationEndPromise;
40
+ this.inputReader = inputReader;
41
+ this.outputWriter = outputWriter;
45
42
  this.invocationRequest = {
46
- id,
47
- headers: invocationHeaders,
48
- attemptHeaders,
49
- body: invocationValue,
43
+ id: input.invocation_id,
44
+ headers: input.headers.reduce((headers, { key, value }) => {
45
+ headers.set(key, value);
46
+ return headers;
47
+ }, new Map()),
48
+ attemptHeaders: Object.entries(attemptHeaders).reduce((headers, [key, value]) => {
49
+ if (value !== undefined) {
50
+ headers.set(key, value instanceof Array ? value[0] : value);
51
+ }
52
+ return headers;
53
+ }, new Map()),
54
+ body: input.input,
50
55
  extraArgs,
51
56
  };
52
- this.rand = new RandImpl(id, this.checkState.bind(this));
53
- }
54
- promise(name, serde) {
55
- return new DurablePromiseImpl(this, name, serde);
57
+ this.rand = new RandImpl(input.invocation_id, () => {
58
+ if (coreVm.is_inside_run()) {
59
+ throw new Error("Cannot generate random numbers within a run closure. Use the random object outside the run closure.");
60
+ }
61
+ });
56
62
  }
57
63
  get key() {
58
64
  switch (this.handlerKind) {
59
65
  case HandlerKind.EXCLUSIVE:
60
66
  case HandlerKind.SHARED:
61
67
  case HandlerKind.WORKFLOW: {
62
- if (this.keyedContextKey === undefined) {
63
- throw new TerminalError("unexpected missing key");
64
- }
65
- return this.keyedContextKey;
68
+ return this.input.key;
66
69
  }
67
- case HandlerKind.SERVICE:
68
- throw new TerminalError("unexpected missing key");
69
70
  default:
70
- throw new TerminalError("unknown handler type");
71
+ throw new TerminalError("this handler type doesn't support key()");
71
72
  }
72
73
  }
73
74
  request() {
74
75
  return this.invocationRequest;
75
76
  }
76
- // DON'T make this function async!!! see sideEffect comment for details.
77
77
  get(name, serde) {
78
- // Check if this is a valid action
79
- this.checkState("get state");
80
- // Create the message and let the state machine process it
81
- const msg = new GetStateEntryMessage({
82
- key: new TextEncoder().encode(name),
83
- });
84
- const completed = this.stateMachine.localStateStore.tryCompleteGet(name, msg);
85
- const getState = async () => {
86
- const result = await this.stateMachine.handleUserCodeMessage(GET_STATE_ENTRY_MESSAGE_TYPE, msg, completed);
87
- // If the GetState message did not have a value or empty,
88
- // then we went to the runtime to get the value.
89
- // When we get the response, we set it in the localStateStore,
90
- // to answer subsequent requests
91
- if (!completed) {
92
- this.stateMachine.localStateStore.add(name, result);
93
- }
94
- if (!(result instanceof Uint8Array)) {
78
+ return this.processCompletableEntry((vm) => vm.sys_get_state(name), (asyncResultValue) => {
79
+ if (asyncResultValue === "Empty") {
80
+ // Empty
95
81
  return null;
96
82
  }
97
- return (serde ?? defaultSerde()).deserialize(result);
98
- };
99
- return getState();
83
+ else if ("Success" in asyncResultValue) {
84
+ return (serde ?? defaultSerde()).deserialize(asyncResultValue.Success);
85
+ }
86
+ else if ("Failure" in asyncResultValue) {
87
+ throw new TerminalError(asyncResultValue.Failure.message, {
88
+ errorCode: asyncResultValue.Failure.code,
89
+ });
90
+ }
91
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
92
+ });
100
93
  }
101
- // DON'T make this function async!!! see sideEffect comment for details.
102
94
  stateKeys() {
103
- // Check if this is a valid action
104
- this.checkState("state keys");
105
- // Create the message and let the state machine process it
106
- const msg = new GetStateKeysEntryMessage({});
107
- const completed = this.stateMachine.localStateStore.tryCompletedGetStateKeys(msg);
108
- const getStateKeys = async () => {
109
- const result = await this.stateMachine.handleUserCodeMessage(GET_STATE_KEYS_ENTRY_MESSAGE_TYPE, msg, completed);
110
- return result.keys.map((b) => new TextDecoder().decode(b));
111
- };
112
- return getStateKeys();
95
+ return this.processCompletableEntry((vm) => vm.sys_get_state_keys(), (asyncResultValue) => {
96
+ if (typeof asyncResultValue === "object" &&
97
+ "StateKeys" in asyncResultValue) {
98
+ return asyncResultValue.StateKeys;
99
+ }
100
+ else if (typeof asyncResultValue === "object" &&
101
+ "Failure" in asyncResultValue) {
102
+ throw new TerminalError(asyncResultValue.Failure.message, {
103
+ errorCode: asyncResultValue.Failure.code,
104
+ });
105
+ }
106
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
107
+ });
113
108
  }
114
109
  set(name, value, serde) {
115
- this.checkState("set state");
116
- const bytes = (serde ?? defaultSerde()).serialize(value);
117
- const msg = this.stateMachine.localStateStore.set(name, bytes);
118
- this.stateMachine
119
- .handleUserCodeMessage(SET_STATE_ENTRY_MESSAGE_TYPE, msg)
120
- .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
110
+ this.processNonCompletableEntry((vm) => vm.sys_set_state(name, (serde ?? defaultSerde()).serialize(value)));
121
111
  }
122
112
  clear(name) {
123
- this.checkState("clear state");
124
- const msg = this.stateMachine.localStateStore.clear(name);
125
- this.stateMachine
126
- .handleUserCodeMessage(CLEAR_STATE_ENTRY_MESSAGE_TYPE, msg)
127
- .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
113
+ this.processNonCompletableEntry((vm) => vm.sys_clear_state(name));
128
114
  }
129
115
  clearAll() {
130
- this.checkState("clear all state");
131
- const msg = this.stateMachine.localStateStore.clearAll();
132
- this.stateMachine
133
- .handleUserCodeMessage(CLEAR_ALL_STATE_ENTRY_MESSAGE_TYPE, msg)
134
- .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
116
+ this.processNonCompletableEntry((vm) => vm.sys_clear_all_state());
135
117
  }
136
118
  // --- Calls, background calls, etc
137
119
  //
138
120
  genericCall(call) {
139
121
  const requestSerde = call.inputSerde ?? serde.binary;
140
122
  const responseSerde = call.outputSerde ?? serde.binary;
141
- const parameter = requestSerde.serialize(call.parameter);
142
- const msg = new CallEntryMessage({
143
- serviceName: call.service,
144
- handlerName: call.method,
145
- parameter,
146
- key: call.key,
123
+ return this.processCompletableEntry((vm) => {
124
+ const parameter = requestSerde.serialize(call.parameter);
125
+ return vm.sys_call(call.service, call.method, parameter, call.key);
126
+ }, (asyncResultValue) => {
127
+ if (typeof asyncResultValue === "object" &&
128
+ "Success" in asyncResultValue) {
129
+ return responseSerde.deserialize(asyncResultValue.Success);
130
+ }
131
+ else if (typeof asyncResultValue === "object" &&
132
+ "Failure" in asyncResultValue) {
133
+ throw new TerminalError(asyncResultValue.Failure.message, {
134
+ errorCode: asyncResultValue.Failure.code,
135
+ });
136
+ }
137
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
147
138
  });
148
- const rawRequest = this.stateMachine.handleUserCodeMessage(INVOKE_ENTRY_MESSAGE_TYPE, msg);
149
- const decoded = rawRequest.transform((res) => responseSerde.deserialize(res));
150
- return this.markCombineablePromise(decoded);
151
139
  }
152
140
  genericSend(send) {
153
- const requestSerde = send.inputSerde ?? serde.binary;
154
- const parameter = requestSerde.serialize(send.parameter);
155
- const actualDelay = send.delay || 0;
156
- const jsInvokeTime = actualDelay > 0 ? Date.now() + actualDelay : protoInt64.zero;
157
- const invokeTime = protoInt64.parse(jsInvokeTime);
158
- const msg = new OneWayCallEntryMessage({
159
- serviceName: send.service,
160
- handlerName: send.method,
161
- parameter,
162
- invokeTime,
163
- key: send.key,
164
- });
165
- this.stateMachine
166
- .handleUserCodeMessage(BACKGROUND_INVOKE_ENTRY_MESSAGE_TYPE, msg)
167
- .catch((e) => {
168
- this.stateMachine.handleDanglingPromiseError(e);
141
+ this.processNonCompletableEntry((vm) => {
142
+ const requestSerde = send.inputSerde ?? serde.binary;
143
+ const parameter = requestSerde.serialize(send.parameter);
144
+ let delay;
145
+ if (send.delay !== undefined) {
146
+ delay = BigInt(send.delay);
147
+ }
148
+ vm.sys_send(send.service, send.method, parameter, send.key, delay);
169
149
  });
170
150
  }
171
151
  serviceClient({ name }) {
@@ -191,224 +171,405 @@ export class ContextImpl {
191
171
  // and not in the promise context. To understand the semantic difference, make this function async and run the
192
172
  // UnawaitedSideEffectShouldFailSubsequentContextCall test.
193
173
  run(nameOrAction, actionSecondParameter, options) {
194
- this.checkState("run");
195
174
  const { name, action } = unpack(nameOrAction, actionSecondParameter);
196
- this.executingRun = true;
197
175
  const serde = options?.serde ?? defaultSerde();
198
- const executeRun = async () => {
199
- // in replay mode, we directly return the value from the log
200
- if (this.stateMachine.nextEntryWillBeReplayed()) {
201
- const emptyMsg = new RunEntryMessage({});
202
- return this.stateMachine
203
- .handleUserCodeMessage(SIDE_EFFECT_ENTRY_MESSAGE_TYPE, emptyMsg)
204
- .transform((result) => {
205
- if (!result || result instanceof Empty) {
206
- return undefined;
207
- }
208
- return serde.deserialize(result);
209
- });
176
+ try {
177
+ const runEnterResult = this.coreVm.sys_run_enter(name || "");
178
+ // Check if the run was already executed
179
+ if (typeof runEnterResult === "object" &&
180
+ "ExecutedWithSuccess" in runEnterResult) {
181
+ return Promise.resolve(serde.deserialize(runEnterResult.ExecutedWithSuccess));
182
+ }
183
+ else if (typeof runEnterResult === "object" &&
184
+ "ExecutedWithFailure" in runEnterResult) {
185
+ return Promise.reject(new TerminalError(runEnterResult.ExecutedWithFailure.message, {
186
+ errorCode: runEnterResult.ExecutedWithFailure.code,
187
+ }));
210
188
  }
211
- let sideEffectResult;
189
+ }
190
+ catch (e) {
191
+ this.handleInvocationEndError(e);
192
+ return pendingPromise();
193
+ }
194
+ // We wrap the rest of the execution in this closure to create a future
195
+ const doRun = async () => {
196
+ const startTime = Date.now();
197
+ let res;
198
+ let err;
212
199
  try {
213
- sideEffectResult = await action();
200
+ res = await action();
214
201
  }
215
202
  catch (e) {
216
- if (!(e instanceof TerminalError)) {
217
- ///non terminal errors are retirable.
218
- // we do not commit the error itself into the journal, but rather let restate know about this
219
- // so that restate can retry this invocation later.
220
- // Before we can propagate this error to the user, we must let the state machine know that this attempt
221
- // is finished with an error, and it should not append anything else to the journal from now on.
222
- const error = ensureError(e);
223
- const additionalContext = {
224
- relatedEntryName: name,
225
- relatedEntryType: SIDE_EFFECT_ENTRY_MESSAGE_TYPE,
226
- };
227
- await this.stateMachine.sendErrorAndFinish(error, additionalContext);
228
- throw e;
203
+ err = ensureError(e);
204
+ }
205
+ const attemptDuration = Date.now() - startTime;
206
+ // Record the result/failure, get back the handle for the ack.
207
+ let handle;
208
+ try {
209
+ if (err !== undefined) {
210
+ if (err instanceof TerminalError) {
211
+ // Record failure, go ahead
212
+ handle = this.coreVm.sys_run_exit_failure({
213
+ code: err.code,
214
+ message: err.message,
215
+ });
216
+ }
217
+ else {
218
+ if (options?.retryIntervalFactor === undefined &&
219
+ options?.initialRetryIntervalMillis === undefined &&
220
+ options?.maxRetryAttempts === undefined &&
221
+ options?.maxRetryDurationMillis === undefined &&
222
+ options?.maxRetryIntervalMillis === undefined) {
223
+ // If no retry option was set, simply throw the error.
224
+ // This will lead to the invoker applying its retry, without the SDK overriding it.
225
+ throw err;
226
+ }
227
+ handle = this.coreVm.sys_run_exit_failure_transient(err.message, err.cause?.toString(), BigInt(attemptDuration), {
228
+ factor: options?.retryIntervalFactor || 2.0,
229
+ initial_interval: options?.initialRetryIntervalMillis || 50,
230
+ max_attempts: options?.maxRetryAttempts,
231
+ max_duration: options?.maxRetryDurationMillis,
232
+ max_interval: options?.maxRetryIntervalMillis || 10 * 1000,
233
+ });
234
+ }
235
+ }
236
+ else {
237
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
238
+ // @ts-expect-error
239
+ handle = this.coreVm.sys_run_exit_success(serde.serialize(res));
229
240
  }
230
- // we commit a terminal error from the side effect to the journal, and re-throw it into
231
- // the function. that way, any catching by the user and reacting to it will be
232
- // deterministic on replay
233
- const error = ensureError(e);
234
- const failure = errorToFailure(error);
235
- const sideEffectMsg = new RunEntryMessage({
236
- name,
237
- result: { case: "failure", value: failure },
238
- });
239
- // this may throw an error from the SDK/runtime/connection side, in case the
240
- // failure message cannot be committed to the journal. That error would then
241
- // be returned from this function (replace the original error)
242
- // that is acceptable, because in such a situation (failure to append to journal),
243
- // the state machine closes anyways and no further operations will succeed and the
244
- // the execution aborts
245
- await this.stateMachine.handleUserCodeMessage(SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, true);
246
- throw e;
247
241
  }
248
- // we have this code outside the above try/catch block, to ensure that any error arising
249
- // from here is not incorrectly attributed to the side-effect
250
- const sideEffectMsg = sideEffectResult !== undefined
251
- ? new RunEntryMessage({
252
- name,
253
- result: {
254
- case: "value",
255
- value: serde.serialize(sideEffectResult),
256
- },
257
- })
258
- : new RunEntryMessage({
259
- name,
260
- });
261
- // if an error arises from committing the side effect result, then this error will
262
- // be thrown here (reject the returned promise) and the function will see that error,
263
- // even if the side-effect function completed correctly
264
- // that is acceptable, because in such a situation (failure to append to journal),
265
- // the state machine closes anyways and reports an execution failure, meaning no further
266
- // operations will succeed and the the execution will be retried.
267
- // If the side-effect result did in fact not make it to the journal, then the side-effect
268
- // re-executes, and if it made it to the journal after all (error happend inly during
269
- // ack-back), then retries will use the journaled result.
270
- // So all good in any case, due to the beauty of "the runtime log is the ground thruth" approach.
271
- await this.stateMachine.handleUserCodeMessage(SIDE_EFFECT_ENTRY_MESSAGE_TYPE, sideEffectMsg, false, true);
272
- return sideEffectResult;
242
+ catch (e) {
243
+ this.handleInvocationEndError(e);
244
+ return pendingPromise();
245
+ }
246
+ // Got the handle, wait for the result now (which we get once we get the ack)
247
+ return await this.pollAsyncResult(handle, (asyncResultValue) => {
248
+ if (typeof asyncResultValue === "object" &&
249
+ "Success" in asyncResultValue) {
250
+ return serde.deserialize(asyncResultValue.Success);
251
+ }
252
+ else if (typeof asyncResultValue === "object" &&
253
+ "Failure" in asyncResultValue) {
254
+ throw new TerminalError(asyncResultValue.Failure.message, {
255
+ errorCode: asyncResultValue.Failure.code,
256
+ });
257
+ }
258
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
259
+ });
273
260
  };
274
- return executeRun().finally(() => {
275
- this.executingRun = false;
276
- });
261
+ return doRun();
277
262
  }
278
263
  sleep(millis) {
279
- this.checkState("sleep");
280
- return this.markCombineablePromise(this.sleepInternal(millis));
281
- }
282
- sleepInternal(millis) {
283
- return this.stateMachine.handleUserCodeMessage(SLEEP_ENTRY_MESSAGE_TYPE, new SleepEntryMessage({
284
- wakeUpTime: protoInt64.parse(Date.now() + millis),
285
- }));
286
- }
287
- // -- Awakeables
288
- awakeable(serde) {
289
- this.checkState("awakeable");
290
- const msg = new AwakeableEntryMessage();
291
- const promise = this.stateMachine
292
- .handleUserCodeMessage(AWAKEABLE_ENTRY_MESSAGE_TYPE, msg)
293
- .transform((result) => {
294
- if (!(result instanceof Uint8Array)) {
295
- // This should either be a filled buffer or an empty buffer but never anything else.
296
- throw RetryableError.internal("Awakeable was not resolved with a buffer payload");
297
- }
298
- if (!serde) {
299
- return defaultSerde().deserialize(result);
300
- }
301
- if (result.length == 0) {
264
+ return this.processCompletableEntry((vm) => vm.sys_sleep(BigInt(millis)), (asyncResultValue) => {
265
+ if (asyncResultValue === "Empty") {
266
+ // Empty
302
267
  return undefined;
303
268
  }
304
- return serde.deserialize(result);
269
+ else if ("Failure" in asyncResultValue) {
270
+ throw new TerminalError(asyncResultValue.Failure.message, {
271
+ errorCode: asyncResultValue.Failure.code,
272
+ });
273
+ }
274
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
305
275
  });
306
- // This needs to be done after handling the message in the state machine
307
- // otherwise the index is not yet incremented.
308
- const encodedEntryIndex = Buffer.alloc(4 /* Size of u32 */);
309
- encodedEntryIndex.writeUInt32BE(this.stateMachine.getUserCodeJournalIndex());
276
+ }
277
+ // -- Awakeables
278
+ awakeable(serde) {
279
+ let awakeable;
280
+ try {
281
+ awakeable = this.coreVm.sys_awakeable();
282
+ }
283
+ catch (e) {
284
+ this.handleInvocationEndError(e);
285
+ return {
286
+ id: "invalid",
287
+ promise: new LazyContextPromise(0, this, () => pendingPromise()),
288
+ };
289
+ }
310
290
  return {
311
- id: AWAKEABLE_IDENTIFIER_PREFIX +
312
- Buffer.concat([this.request().id, encodedEntryIndex]).toString("base64url"),
313
- promise: this.markCombineablePromise(promise),
291
+ id: awakeable.id,
292
+ promise: new LazyContextPromise(awakeable.handle, this, () => this.pollAsyncResult(awakeable.handle, (asyncResultValue) => {
293
+ if (typeof asyncResultValue === "object" &&
294
+ "Success" in asyncResultValue) {
295
+ if (!serde) {
296
+ return defaultSerde().deserialize(asyncResultValue.Success);
297
+ }
298
+ if (asyncResultValue.Success.length === 0) {
299
+ return undefined;
300
+ }
301
+ return serde.deserialize(asyncResultValue.Success);
302
+ }
303
+ else if (typeof asyncResultValue === "object" &&
304
+ "Failure" in asyncResultValue) {
305
+ throw new TerminalError(asyncResultValue.Failure.message, {
306
+ errorCode: asyncResultValue.Failure.code,
307
+ });
308
+ }
309
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
310
+ })),
314
311
  };
315
312
  }
316
313
  resolveAwakeable(id, payload, serde) {
317
- // We coerce undefined to null as null can be stringified by JSON.stringify
318
- let value;
319
- if (serde) {
320
- value =
321
- payload == undefined ? new Uint8Array() : serde.serialize(payload);
322
- }
323
- else {
324
- value =
325
- payload != undefined
326
- ? defaultSerde().serialize(payload)
327
- : defaultSerde().serialize(null);
328
- }
329
- this.checkState("resolveAwakeable");
330
- this.completeAwakeable(id, {
331
- result: {
332
- case: "value",
333
- value,
334
- },
314
+ this.processNonCompletableEntry((vm) => {
315
+ // We coerce undefined to null as null can be stringified by JSON.stringify
316
+ let value;
317
+ if (serde) {
318
+ value =
319
+ payload === undefined ? new Uint8Array() : serde.serialize(payload);
320
+ }
321
+ else {
322
+ value =
323
+ payload !== undefined
324
+ ? defaultSerde().serialize(payload)
325
+ : defaultSerde().serialize(null);
326
+ }
327
+ vm.sys_complete_awakeable_success(id, value);
335
328
  });
336
329
  }
337
330
  rejectAwakeable(id, reason) {
338
- this.checkState("rejectAwakeable");
339
- this.completeAwakeable(id, {
340
- result: {
341
- case: "failure",
342
- value: { code: UNKNOWN_ERROR_CODE, message: reason },
343
- },
331
+ this.processNonCompletableEntry((vm) => {
332
+ vm.sys_complete_awakeable_failure(id, {
333
+ code: UNKNOWN_ERROR_CODE,
334
+ message: reason,
335
+ });
344
336
  });
345
337
  }
346
- completeAwakeable(id, base) {
347
- base.id = id;
348
- this.stateMachine
349
- .handleUserCodeMessage(COMPLETE_AWAKEABLE_ENTRY_MESSAGE_TYPE, new CompleteAwakeableEntryMessage(base))
350
- .catch((e) => this.stateMachine.handleDanglingPromiseError(e));
338
+ promise(name, serde) {
339
+ return new DurablePromiseImpl(this, name, serde);
351
340
  }
352
341
  // Used by static methods of CombineablePromise
353
- static createCombinator(combinatorConstructor, promises) {
342
+ static createCombinator(combinatorType, promises) {
343
+ // Extract context from first promise
354
344
  const self = extractContext(promises[0]);
355
345
  if (!self) {
356
- throw RetryableError.internal("Not a combinable promise");
346
+ throw new Error("Not a combinable promise");
357
347
  }
358
- const outPromises = [];
348
+ // Collect first the promises downcasted to the internal promise type
349
+ const castedPromises = [];
359
350
  for (const promise of promises) {
360
351
  if (extractContext(promise) !== self) {
361
- throw RetryableError.internal("You're mixing up CombineablePromises from different RestateContext. This is not supported.");
352
+ self.handleInvocationEndError(new Error("You're mixing up CombineablePromises from different RestateContext. This is not supported."));
353
+ return pendingPromise();
354
+ }
355
+ castedPromises.push(promise);
356
+ }
357
+ const handles = new Uint32Array(castedPromises.map((p) => p.asyncResultHandle));
358
+ // From now on, lazily executes on await
359
+ return new LazyPromise(async () => {
360
+ let combinatorResultHandle;
361
+ try {
362
+ // Take output
363
+ const nextOutput1 = self.coreVm.take_output();
364
+ if (nextOutput1 instanceof Uint8Array) {
365
+ await self.outputWriter.write(nextOutput1);
366
+ }
367
+ for (;;) {
368
+ switch (combinatorType) {
369
+ case "All":
370
+ combinatorResultHandle =
371
+ self.coreVm.sys_try_complete_all_combinator(handles);
372
+ break;
373
+ case "Any":
374
+ combinatorResultHandle =
375
+ self.coreVm.sys_try_complete_any_combinator(handles);
376
+ break;
377
+ case "AllSettled":
378
+ combinatorResultHandle =
379
+ self.coreVm.sys_try_complete_all_settled_combinator(handles);
380
+ break;
381
+ case "Race":
382
+ case "OrTimeout":
383
+ combinatorResultHandle =
384
+ self.coreVm.sys_try_complete_race_combinator(handles);
385
+ break;
386
+ }
387
+ // We got a result, we're done in this loop
388
+ if (combinatorResultHandle !== undefined) {
389
+ break;
390
+ }
391
+ // No result yet, await the next read
392
+ await self.awaitNextRead();
393
+ }
394
+ // We got a result, we need to take_output to write the combinator entry, then we need to poll the result
395
+ const nextOutput = self.coreVm.take_output();
396
+ if (nextOutput instanceof Uint8Array) {
397
+ await self.outputWriter.write(nextOutput);
398
+ }
399
+ }
400
+ catch (e) {
401
+ if (e instanceof TerminalError) {
402
+ // All good, this is a recorded failure
403
+ throw e;
404
+ }
405
+ // Not good, this is a retryable error.
406
+ self.handleInvocationEndError(e);
407
+ return await pendingPromise();
362
408
  }
363
- const index = promise
364
- .journalIndex;
365
- outPromises.push({
366
- id: newJournalEntryPromiseId(index),
367
- promise: promise,
409
+ const handlesResult = await self.pollAsyncResult(combinatorResultHandle, (asyncResultValue) => {
410
+ if (typeof asyncResultValue === "object" &&
411
+ "CombinatorResult" in asyncResultValue) {
412
+ return asyncResultValue.CombinatorResult;
413
+ }
414
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
368
415
  });
416
+ const promisesMap = new Map(castedPromises.map((p) => [p.asyncResultHandle, p]));
417
+ // Now all we need to do is to construct the final output based on the handles,
418
+ // this depends on combinators themselves.
419
+ switch (combinatorType) {
420
+ case "All":
421
+ return this.extractAllCombinatorResult(handlesResult, promisesMap);
422
+ case "Any":
423
+ return this.extractAnyCombinatorResult(handlesResult, promisesMap);
424
+ case "AllSettled":
425
+ return this.extractAllSettledCombinatorResult(handlesResult, promisesMap);
426
+ case "Race":
427
+ // Just one promise succeeded
428
+ return promisesMap.get(handlesResult[0]);
429
+ case "OrTimeout":
430
+ // The sleep promise is always the second one in the list.
431
+ if (handlesResult[0] === castedPromises[1].asyncResultHandle) {
432
+ return Promise.reject(new TimeoutError());
433
+ }
434
+ else {
435
+ return promisesMap.get(handlesResult[0]);
436
+ }
437
+ }
438
+ });
439
+ }
440
+ static async extractAllCombinatorResult(handlesResult, promisesMap) {
441
+ // The result can either all values, or one error
442
+ const resultValues = [];
443
+ for (const handle of handlesResult) {
444
+ try {
445
+ resultValues.push(await promisesMap.get(handle));
446
+ }
447
+ catch (e) {
448
+ return Promise.reject(e);
449
+ }
450
+ }
451
+ return Promise.resolve(resultValues);
452
+ }
453
+ static async extractAnyCombinatorResult(handlesResult, promisesMap) {
454
+ // The result can either be one value, or a list of errors
455
+ const resultFailures = [];
456
+ for (const handle of handlesResult) {
457
+ try {
458
+ return Promise.resolve(await promisesMap.get(handle));
459
+ }
460
+ catch (e) {
461
+ resultFailures.push(e);
462
+ }
463
+ }
464
+ // Giving back the cause here is completely fine, because all these errors in Aggregate error are Terminal errors!
465
+ return Promise.reject(new TerminalError("All input promises failed", {
466
+ cause: new AggregateError(resultFailures),
467
+ }));
468
+ }
469
+ static async extractAllSettledCombinatorResult(handlesResult, promisesMap) {
470
+ const resultValues = [];
471
+ for (const handle of handlesResult) {
472
+ try {
473
+ resultValues.push(await promisesMap.get(handle));
474
+ }
475
+ catch (e) {
476
+ resultValues.push(e);
477
+ }
369
478
  }
370
- return self.stateMachine.createCombinator(combinatorConstructor, outPromises);
479
+ return Promise.resolve(resultValues);
371
480
  }
372
481
  // -- Various private methods
373
- checkNotExecutingRun(callType) {
374
- if (this.executingRun) {
375
- throw new TerminalError(`Invoked a RestateContext method (${callType}) while a run() is still executing.
376
- Make sure you await the ctx.run() call before using any other RestateContext method.`, { errorCode: INTERNAL_ERROR_CODE });
482
+ processNonCompletableEntry(vmCall) {
483
+ try {
484
+ vmCall(this.coreVm);
485
+ }
486
+ catch (e) {
487
+ this.handleInvocationEndError(e);
377
488
  }
378
489
  }
379
- checkState(callType) {
380
- this.checkNotExecutingRun(callType);
490
+ processCompletableEntry(vmCall, transformer) {
491
+ let handle;
492
+ try {
493
+ handle = vmCall(this.coreVm);
494
+ }
495
+ catch (e) {
496
+ this.handleInvocationEndError(e);
497
+ return new LazyContextPromise(0, this, () => pendingPromise());
498
+ }
499
+ return new LazyContextPromise(handle, this, () => this.pollAsyncResult(handle, transformer));
500
+ }
501
+ async pollAsyncResult(handle, transformer) {
502
+ try {
503
+ // Take output
504
+ const nextOutput = this.coreVm.take_output();
505
+ if (nextOutput instanceof Uint8Array) {
506
+ await this.outputWriter.write(nextOutput);
507
+ }
508
+ // Now loop waiting for the async result
509
+ let asyncResult = this.coreVm.take_async_result(handle);
510
+ while (asyncResult === "NotReady") {
511
+ await this.awaitNextRead();
512
+ // Using notify_await_point immediately before take_async_result
513
+ // makes sure the state machine will try to suspend only now,
514
+ // in case there aren't other concurrent tasks trying to poll this async result.
515
+ this.coreVm.notify_await_point(handle);
516
+ asyncResult = this.coreVm.take_async_result(handle);
517
+ }
518
+ return transformer(asyncResult);
519
+ }
520
+ catch (e) {
521
+ if (e instanceof TerminalError) {
522
+ // All good, this is a recorded failure
523
+ throw e;
524
+ }
525
+ // Not good, this is a retryable error.
526
+ this.handleInvocationEndError(e);
527
+ return await pendingPromise();
528
+ }
381
529
  }
382
- markCombineablePromise(p) {
383
- const journalIndex = this.stateMachine.getUserCodeJournalIndex();
384
- const orTimeout = (millis) => {
385
- const sleepPromise = this.sleepInternal(millis).transform(() => {
386
- throw new TimeoutError();
530
+ // This function triggers a read on the input reader,
531
+ // and will notify the caller that a read was executed
532
+ // and the result was piped in the state machine.
533
+ awaitNextRead() {
534
+ if (this.currentRead === undefined) {
535
+ // Register a new read
536
+ this.currentRead = this.readNext().finally(() => {
537
+ this.currentRead = undefined;
387
538
  });
388
- const sleepPromiseIndex = this.stateMachine.getUserCodeJournalIndex();
389
- return this.stateMachine.createCombinator(Promise.race.bind(Promise), [
390
- {
391
- id: newJournalEntryPromiseId(journalIndex),
392
- promise: p,
393
- },
394
- {
395
- id: newJournalEntryPromiseId(sleepPromiseIndex),
396
- promise: sleepPromise,
397
- },
398
- ]);
399
- };
400
- defineProperty(p, RESTATE_CTX_SYMBOL, this);
401
- defineProperty(p, "journalIndex", journalIndex);
402
- defineProperty(p, "orTimeout", orTimeout.bind(this));
403
- return p;
539
+ }
540
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
541
+ return new Promise((resolve) => this.currentRead?.finally(resolve));
542
+ }
543
+ async readNext() {
544
+ // Take input, and notify it to the vm
545
+ let nextValue;
546
+ try {
547
+ nextValue = await this.inputReader.read();
548
+ }
549
+ catch (e) {
550
+ this.handleInvocationEndError(e);
551
+ return pendingPromise();
552
+ }
553
+ if (nextValue.value !== undefined) {
554
+ this.coreVm.notify_input(nextValue.value);
555
+ }
556
+ if (nextValue.done) {
557
+ this.coreVm.notify_input_closed();
558
+ }
559
+ }
560
+ handleInvocationEndError(e) {
561
+ const error = ensureError(e);
562
+ if (!(error instanceof RestateError) ||
563
+ error.code !== SUSPENDED_ERROR_CODE) {
564
+ this.console.warn("Function completed with an error.\n", error);
565
+ }
566
+ this.coreVm.notify_error(error.message, error.stack);
567
+ // From now on, no progress will be made.
568
+ this.invocationEndPromise.resolve();
404
569
  }
405
- }
406
- // wraps defineProperty such that it informs tsc of the correct type of its output
407
- function defineProperty(obj, prop, value) {
408
- Object.defineProperty(obj, prop, { value });
409
570
  }
410
571
  function unpack(a, b) {
411
- if (typeof a == "string") {
572
+ if (typeof a === "string") {
412
573
  if (typeof b !== "function") {
413
574
  throw new TypeError("");
414
575
  }
@@ -448,56 +609,108 @@ class DurablePromiseImpl {
448
609
  }
449
610
  [Symbol.toStringTag] = "DurablePromise";
450
611
  get() {
451
- const msg = new GetPromiseEntryMessage({
452
- key: this.name,
453
- });
454
- return this.ctx.markCombineablePromise(this.ctx.stateMachine
455
- .handleUserCodeMessage(GET_PROMISE_MESSAGE_TYPE, msg)
456
- .transform((v) => {
457
- if (!v) {
458
- return undefined;
612
+ return this.ctx.processCompletableEntry((vm) => vm.sys_get_promise(this.name), (asyncResultValue) => {
613
+ if (typeof asyncResultValue === "object" &&
614
+ "Success" in asyncResultValue) {
615
+ return this.serde.deserialize(asyncResultValue.Success);
459
616
  }
460
- if (v instanceof Empty) {
461
- return undefined;
617
+ else if (typeof asyncResultValue === "object" &&
618
+ "Failure" in asyncResultValue) {
619
+ throw new TerminalError(asyncResultValue.Failure.message, {
620
+ errorCode: asyncResultValue.Failure.code,
621
+ });
462
622
  }
463
- return this.serde.deserialize(v);
464
- }));
623
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
624
+ });
465
625
  }
466
626
  peek() {
467
- const msg = new PeekPromiseEntryMessage({
468
- key: this.name,
469
- });
470
- return this.ctx.stateMachine
471
- .handleUserCodeMessage(PEEK_PROMISE_MESSAGE_TYPE, msg)
472
- .transform((v) => {
473
- if (!v || v instanceof Empty) {
627
+ return this.ctx.processCompletableEntry((vm) => vm.sys_peek_promise(this.name), (asyncResultValue) => {
628
+ if (asyncResultValue === "Empty") {
474
629
  return undefined;
475
630
  }
476
- return this.serde.deserialize(v);
631
+ else if (typeof asyncResultValue === "object" &&
632
+ "Success" in asyncResultValue) {
633
+ return this.serde.deserialize(asyncResultValue.Success);
634
+ }
635
+ else if (typeof asyncResultValue === "object" &&
636
+ "Failure" in asyncResultValue) {
637
+ throw new TerminalError(asyncResultValue.Failure.message, {
638
+ errorCode: asyncResultValue.Failure.code,
639
+ });
640
+ }
641
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
477
642
  });
478
643
  }
479
644
  resolve(value) {
480
- const buffer = value != undefined ? this.serde.serialize(value) : new Uint8Array();
481
- const msg = new CompletePromiseEntryMessage({
482
- key: this.name,
483
- completion: {
484
- case: "completionValue",
485
- value: buffer,
486
- },
645
+ return this.ctx.processCompletableEntry((vm) => vm.sys_complete_promise_success(this.name, this.serde.serialize(value)), (asyncResultValue) => {
646
+ if (asyncResultValue === "Empty") {
647
+ return undefined;
648
+ }
649
+ else if (typeof asyncResultValue === "object" &&
650
+ "Failure" in asyncResultValue) {
651
+ throw new TerminalError(asyncResultValue.Failure.message, {
652
+ errorCode: asyncResultValue.Failure.code,
653
+ });
654
+ }
655
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
487
656
  });
488
- return this.ctx.stateMachine.handleUserCodeMessage(COMPLETE_PROMISE_MESSAGE_TYPE, msg);
489
657
  }
490
658
  reject(errorMsg) {
491
- const msg = new CompletePromiseEntryMessage({
492
- key: this.name,
493
- completion: {
494
- case: "completionFailure",
495
- value: {
496
- message: errorMsg,
497
- },
498
- },
659
+ return this.ctx.processCompletableEntry((vm) => vm.sys_complete_promise_failure(this.name, {
660
+ code: INTERNAL_ERROR_CODE,
661
+ message: errorMsg,
662
+ }), (asyncResultValue) => {
663
+ if (asyncResultValue === "Empty") {
664
+ return undefined;
665
+ }
666
+ else if (typeof asyncResultValue === "object" &&
667
+ "Failure" in asyncResultValue) {
668
+ throw new TerminalError(asyncResultValue.Failure.message, {
669
+ errorCode: asyncResultValue.Failure.code,
670
+ });
671
+ }
672
+ throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
499
673
  });
500
- return this.ctx.stateMachine.handleUserCodeMessage(COMPLETE_PROMISE_MESSAGE_TYPE, msg);
501
674
  }
502
675
  }
676
+ class LazyPromise {
677
+ executor;
678
+ _promise;
679
+ constructor(executor) {
680
+ this.executor = executor;
681
+ }
682
+ then(onfulfilled, onrejected) {
683
+ this._promise = this._promise || this.executor();
684
+ return this._promise.then(onfulfilled, onrejected);
685
+ }
686
+ catch(onrejected) {
687
+ this._promise = this._promise || this.executor();
688
+ return this._promise.catch(onrejected);
689
+ }
690
+ finally(onfinally) {
691
+ this._promise = this._promise || this.executor();
692
+ return this._promise.finally(onfinally);
693
+ }
694
+ [Symbol.toStringTag] = "LazyPromise";
695
+ }
696
+ class LazyContextPromise extends LazyPromise {
697
+ asyncResultHandle;
698
+ [RESTATE_CTX_SYMBOL];
699
+ constructor(asyncResultHandle, ctx, executor) {
700
+ super(executor);
701
+ this.asyncResultHandle = asyncResultHandle;
702
+ this[RESTATE_CTX_SYMBOL] = ctx;
703
+ }
704
+ orTimeout(millis) {
705
+ return ContextImpl.createCombinator("OrTimeout", [
706
+ this,
707
+ this[RESTATE_CTX_SYMBOL].sleep(millis),
708
+ ]);
709
+ }
710
+ }
711
+ // A promise that is never completed
712
+ function pendingPromise() {
713
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
714
+ return new Promise(() => { });
715
+ }
503
716
  //# sourceMappingURL=context_impl.js.map