@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.
- 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
|
@@ -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 {
|
|
12
|
-
import {
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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.
|
|
44
|
-
this.
|
|
39
|
+
this.invocationEndPromise = invocationEndPromise;
|
|
40
|
+
this.inputReader = inputReader;
|
|
41
|
+
this.outputWriter = outputWriter;
|
|
45
42
|
this.invocationRequest = {
|
|
46
|
-
id,
|
|
47
|
-
headers:
|
|
48
|
-
|
|
49
|
-
|
|
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(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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("
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
if
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
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
|
-
|
|
200
|
+
res = await action();
|
|
214
201
|
}
|
|
215
202
|
catch (e) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
|
275
|
-
this.executingRun = false;
|
|
276
|
-
});
|
|
261
|
+
return doRun();
|
|
277
262
|
}
|
|
278
263
|
sleep(millis) {
|
|
279
|
-
this.
|
|
280
|
-
|
|
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
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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:
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
347
|
-
|
|
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(
|
|
342
|
+
static createCombinator(combinatorType, promises) {
|
|
343
|
+
// Extract context from first promise
|
|
354
344
|
const self = extractContext(promises[0]);
|
|
355
345
|
if (!self) {
|
|
356
|
-
throw
|
|
346
|
+
throw new Error("Not a combinable promise");
|
|
357
347
|
}
|
|
358
|
-
|
|
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
|
-
|
|
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
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
|
479
|
+
return Promise.resolve(resultValues);
|
|
371
480
|
}
|
|
372
481
|
// -- Various private methods
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
482
|
+
processNonCompletableEntry(vmCall) {
|
|
483
|
+
try {
|
|
484
|
+
vmCall(this.coreVm);
|
|
485
|
+
}
|
|
486
|
+
catch (e) {
|
|
487
|
+
this.handleInvocationEndError(e);
|
|
377
488
|
}
|
|
378
489
|
}
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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 (
|
|
461
|
-
|
|
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
|
-
|
|
464
|
-
})
|
|
623
|
+
throw new Error(`Unexpected variant in async result: ${JSON.stringify(asyncResultValue)}`);
|
|
624
|
+
});
|
|
465
625
|
}
|
|
466
626
|
peek() {
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
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
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|