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