@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
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PromiseCombinatorTracker = exports.newJournalEntryPromiseId = exports.PromiseType = void 0;
|
|
4
|
-
const promises_js_1 = require("./utils/promises.js");
|
|
5
|
-
var PromiseType;
|
|
6
|
-
(function (PromiseType) {
|
|
7
|
-
PromiseType[PromiseType["JournalEntry"] = 0] = "JournalEntry";
|
|
8
|
-
// Combinator?,
|
|
9
|
-
// SideEffect?
|
|
10
|
-
})(PromiseType || (exports.PromiseType = PromiseType = {}));
|
|
11
|
-
function newJournalEntryPromiseId(entryIndex) {
|
|
12
|
-
return {
|
|
13
|
-
type: PromiseType.JournalEntry,
|
|
14
|
-
id: entryIndex,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
exports.newJournalEntryPromiseId = newJournalEntryPromiseId;
|
|
18
|
-
/**
|
|
19
|
-
* Prepare a Promise combinator
|
|
20
|
-
*
|
|
21
|
-
* @param combinatorIndex the index of this combinator
|
|
22
|
-
* @param combinatorConstructor the function that creates the combinator promise, e.g. Promise.all/any/race/allSettled
|
|
23
|
-
* @param promises the promises given by the user, and the respective ids
|
|
24
|
-
* @param readReplayOrder the function to read the replay order
|
|
25
|
-
* @param onNewCompleted callback when a child entry is resolved
|
|
26
|
-
* @param onCombinatorResolved callback when the combinator is resolved
|
|
27
|
-
* @param onCombinatorReplayed callback when the combinator is replayed
|
|
28
|
-
*/
|
|
29
|
-
function preparePromiseCombinator(combinatorIndex, combinatorConstructor, promises, readReplayOrder, onNewCompleted, onCombinatorResolved, onCombinatorReplayed) {
|
|
30
|
-
// Create the proxy promises and index them
|
|
31
|
-
const promisesWithProxyPromise = promises.map((v) => ({
|
|
32
|
-
id: v.id,
|
|
33
|
-
originalPromise: v.promise,
|
|
34
|
-
proxyPromise: new promises_js_1.CompletablePromise(),
|
|
35
|
-
}));
|
|
36
|
-
const promisesMap = new Map(promisesWithProxyPromise.map((v) => [
|
|
37
|
-
// We need to define a key format for this map...
|
|
38
|
-
v.id.type.toString() + "-" + v.id.id.toString(),
|
|
39
|
-
{ originalPromise: v.originalPromise, proxyPromise: v.proxyPromise },
|
|
40
|
-
]));
|
|
41
|
-
// Create the combinator using the proxy promises
|
|
42
|
-
const combinator = combinatorConstructor(promisesWithProxyPromise.map((v) => v.proxyPromise.promise)).finally(
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
44
|
-
async () =>
|
|
45
|
-
// Once the combinator is resolved, notify back.
|
|
46
|
-
await onCombinatorResolved(combinatorIndex));
|
|
47
|
-
return (0, promises_js_1.wrapDeeply)(combinator, () => {
|
|
48
|
-
const replayOrder = readReplayOrder(combinatorIndex);
|
|
49
|
-
if (replayOrder === undefined) {
|
|
50
|
-
// We're in processing mode! We need to wire up original promises with proxy promises
|
|
51
|
-
for (const { originalPromise, proxyPromise, id, } of promisesWithProxyPromise) {
|
|
52
|
-
originalPromise
|
|
53
|
-
// This code works deterministically because the javascript runtime will enqueue
|
|
54
|
-
// the listeners of the proxy promise (which are mounted in Promise.all/any) in a single FIFO queue,
|
|
55
|
-
// so a subsequent resolve on another proxy promise can't overtake this one.
|
|
56
|
-
//
|
|
57
|
-
// Some resources:
|
|
58
|
-
// * https://stackoverflow.com/questions/38059284/why-does-javascript-promise-then-handler-run-after-other-code
|
|
59
|
-
// * https://262.ecma-international.org/6.0/#sec-jobs-and-job-queues
|
|
60
|
-
// * https://tr.javascript.info/microtask-queue
|
|
61
|
-
.then((v) => {
|
|
62
|
-
onNewCompleted(combinatorIndex, id);
|
|
63
|
-
proxyPromise.resolve(v);
|
|
64
|
-
}, (e) => {
|
|
65
|
-
onNewCompleted(combinatorIndex, id);
|
|
66
|
-
proxyPromise.reject(e);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// We're in replay mode, Now follow the replayIndexes order.
|
|
72
|
-
onCombinatorReplayed(combinatorIndex);
|
|
73
|
-
for (const promiseId of replayOrder) {
|
|
74
|
-
// These are already completed, so once we set the then callback they will be immediately resolved.
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
76
|
-
const { originalPromise, proxyPromise } = promisesMap.get(promiseId.type.toString() + "-" + promiseId.id.toString());
|
|
77
|
-
// Because this promise is already completed, promise.then will immediately enqueue in the promise microtask queue
|
|
78
|
-
// the handlers to execute.
|
|
79
|
-
// See the comment below for more details.
|
|
80
|
-
originalPromise.then((v) => proxyPromise.resolve(v), (e) => proxyPromise.reject(e));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* This class takes care of creating and managing deterministic promise combinators.
|
|
86
|
-
*
|
|
87
|
-
* It should be wired up to the journal/state machine methods to read and write entries.
|
|
88
|
-
*/
|
|
89
|
-
class PromiseCombinatorTracker {
|
|
90
|
-
readReplayOrder;
|
|
91
|
-
onWriteCombinatorOrder;
|
|
92
|
-
nextCombinatorIndex = 0;
|
|
93
|
-
pendingCombinators = new Map();
|
|
94
|
-
constructor(readReplayOrder, onWriteCombinatorOrder) {
|
|
95
|
-
this.readReplayOrder = readReplayOrder;
|
|
96
|
-
this.onWriteCombinatorOrder = onWriteCombinatorOrder;
|
|
97
|
-
}
|
|
98
|
-
createCombinator(combinatorConstructor, promises) {
|
|
99
|
-
const combinatorIndex = this.nextCombinatorIndex;
|
|
100
|
-
this.nextCombinatorIndex++;
|
|
101
|
-
// Prepare combinator order
|
|
102
|
-
this.pendingCombinators.set(combinatorIndex, []);
|
|
103
|
-
return preparePromiseCombinator(combinatorIndex, combinatorConstructor, promises, this.readReplayOrder, this.appendOrder.bind(this), this.onCombinatorResolved.bind(this), this.onCombinatorReplayed.bind(this));
|
|
104
|
-
}
|
|
105
|
-
appendOrder(idx, promiseId) {
|
|
106
|
-
const order = this.pendingCombinators.get(idx);
|
|
107
|
-
if (order === undefined) {
|
|
108
|
-
// The order was already published, nothing to do here.
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
order.push(promiseId);
|
|
112
|
-
}
|
|
113
|
-
onCombinatorReplayed(idx) {
|
|
114
|
-
// This avoids republishing the order
|
|
115
|
-
this.pendingCombinators.delete(idx);
|
|
116
|
-
}
|
|
117
|
-
async onCombinatorResolved(idx) {
|
|
118
|
-
const order = this.pendingCombinators.get(idx);
|
|
119
|
-
if (order === undefined) {
|
|
120
|
-
// It was already published
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
// We don't need this list anymore.
|
|
124
|
-
this.pendingCombinators.delete(idx);
|
|
125
|
-
// Publish the combinator order
|
|
126
|
-
await this.onWriteCombinatorOrder(idx, order);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.PromiseCombinatorTracker = PromiseCombinatorTracker;
|
|
130
|
-
//# sourceMappingURL=promise_combinator_tracker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promise_combinator_tracker.js","sourceRoot":"","sources":["../../../src/promise_combinator_tracker.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as p from "./types/protocol.js";
|
|
3
|
-
import type { Connection, RestateStreamConsumer } from "./connection/connection.js";
|
|
4
|
-
import { Message } from "./types/types.js";
|
|
5
|
-
import type { StateMachineConsole } from "./utils/message_logger.js";
|
|
6
|
-
import type { Invocation } from "./invocation.js";
|
|
7
|
-
import type { JournalErrorContext } from "./types/errors.js";
|
|
8
|
-
import type { LocalStateStore } from "./local_state_store.js";
|
|
9
|
-
import type { Logger, LoggerContext } from "./logger.js";
|
|
10
|
-
import type { WrappedPromise } from "./utils/promises.js";
|
|
11
|
-
import type { PromiseId } from "./promise_combinator_tracker.js";
|
|
12
|
-
import { Buffer } from "node:buffer";
|
|
13
|
-
import type { HandlerKind } from "./types/rpc.js";
|
|
14
|
-
import type { Empty } from "./generated/proto/protocol_pb.js";
|
|
15
|
-
export declare class StateMachine implements RestateStreamConsumer {
|
|
16
|
-
private readonly connection;
|
|
17
|
-
private readonly invocation;
|
|
18
|
-
private readonly suspensionMillis;
|
|
19
|
-
private journal;
|
|
20
|
-
private restateContext;
|
|
21
|
-
private readonly invocationComplete;
|
|
22
|
-
private stateMachineClosed;
|
|
23
|
-
readonly localStateStore: LocalStateStore;
|
|
24
|
-
private inputChannelClosed;
|
|
25
|
-
private suspensionTimeout?;
|
|
26
|
-
private promiseCombinatorTracker;
|
|
27
|
-
console: StateMachineConsole;
|
|
28
|
-
constructor(connection: Connection, invocation: Invocation, handlerKind: HandlerKind, logger: Logger, loggerContext: LoggerContext, extraArgs: unknown[], suspensionMillis?: number);
|
|
29
|
-
handleMessage(m: Message): boolean;
|
|
30
|
-
handleUserCodeMessage(messageType: bigint, message: p.ProtocolMessage, completedFlag?: boolean, requiresAckFlag?: boolean): WrappedPromise<Uint8Array | Empty | void>;
|
|
31
|
-
createCombinator(combinatorConstructor: (promises: PromiseLike<unknown>[]) => Promise<unknown>, promises: Array<{
|
|
32
|
-
id: PromiseId;
|
|
33
|
-
promise: Promise<unknown>;
|
|
34
|
-
}>): WrappedPromise<unknown>;
|
|
35
|
-
readCombinatorOrderEntry(combinatorId: number): PromiseId[] | undefined;
|
|
36
|
-
writeCombinatorOrderEntry(combinatorId: number, order: PromiseId[]): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Invokes the RPC function and returns a promise that completes when the state machine
|
|
39
|
-
* stops processing the invocation, meaning when:
|
|
40
|
-
* - The function completes with a result or an exception
|
|
41
|
-
* - The execution suspends
|
|
42
|
-
* - An error is raised in the state machine (network, API violation, ...)
|
|
43
|
-
*
|
|
44
|
-
* The returned promise resolves successfully for all the cases above, because the are (from
|
|
45
|
-
* the perspective of the state machine) expected outcomes in which it send out corresponding
|
|
46
|
-
* result messages and cleanly closed the connection.
|
|
47
|
-
*
|
|
48
|
-
* The returned promise is rejected when an unhandled error arises and the caller would be
|
|
49
|
-
* expected to ensure that resources are properly cleaned up.
|
|
50
|
-
*/
|
|
51
|
-
invoke(): Promise<Buffer | void>;
|
|
52
|
-
sendErrorAndFinish(e: Error, ctx?: JournalErrorContext): Promise<void>;
|
|
53
|
-
private sendRetryableError;
|
|
54
|
-
private sendTerminalError;
|
|
55
|
-
private send;
|
|
56
|
-
/**
|
|
57
|
-
* Closes the state machine, flushes all output, and resolves the invocation promise.
|
|
58
|
-
*/
|
|
59
|
-
private finish;
|
|
60
|
-
/**
|
|
61
|
-
* This function propagates errors up to the completion promise, to be handled
|
|
62
|
-
* on the connection layer.
|
|
63
|
-
*/
|
|
64
|
-
private unhandledError;
|
|
65
|
-
/**
|
|
66
|
-
* This method is invoked when we hit a suspension point. A suspension point is everytime the user "await"s a Promise returned by RestateContext that might be completed at a later point in time by a CompletionMessage/AckMessage.
|
|
67
|
-
*
|
|
68
|
-
* Depending on the state of the read channel, it might either immediately suspend, or schedule a suspension to happen at a later point in time.
|
|
69
|
-
*/
|
|
70
|
-
private hitSuspensionPoint;
|
|
71
|
-
private getSuspensionMillis;
|
|
72
|
-
private suspend;
|
|
73
|
-
/**
|
|
74
|
-
* WARNING: make sure you use this at the right point in the code
|
|
75
|
-
* After the index has been incremented...
|
|
76
|
-
* This is error-prone... Would be good to have a better solution for this.
|
|
77
|
-
*/
|
|
78
|
-
getUserCodeJournalIndex(): number;
|
|
79
|
-
handleInputClosed(): void;
|
|
80
|
-
handleStreamError(e: Error): void;
|
|
81
|
-
handleDanglingPromiseError(e: Error): void;
|
|
82
|
-
nextEntryWillBeReplayed(): boolean;
|
|
83
|
-
private clearSuspensionTimeout;
|
|
84
|
-
}
|
|
85
|
-
//# sourceMappingURL=state_machine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"state_machine.d.ts","sourceRoot":"","sources":["../../../src/state_machine.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,426 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
6
|
-
* which is released under the MIT license.
|
|
7
|
-
*
|
|
8
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
9
|
-
* directory of this repository or package, or at
|
|
10
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
11
|
-
*/
|
|
12
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
-
}
|
|
18
|
-
Object.defineProperty(o, k2, desc);
|
|
19
|
-
}) : (function(o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
o[k2] = m[k];
|
|
22
|
-
}));
|
|
23
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
-
}) : function(o, v) {
|
|
26
|
-
o["default"] = v;
|
|
27
|
-
});
|
|
28
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.StateMachine = void 0;
|
|
37
|
-
const p = __importStar(require("./types/protocol.js"));
|
|
38
|
-
const context_impl_js_1 = require("./context_impl.js");
|
|
39
|
-
const types_js_1 = require("./types/types.js");
|
|
40
|
-
const message_logger_js_1 = require("./utils/message_logger.js");
|
|
41
|
-
const protocol_js_1 = require("./types/protocol.js");
|
|
42
|
-
const journal_js_1 = require("./journal.js");
|
|
43
|
-
const errors_js_1 = require("./types/errors.js");
|
|
44
|
-
const logger_js_1 = require("./logger.js");
|
|
45
|
-
const promises_js_1 = require("./utils/promises.js");
|
|
46
|
-
const promise_combinator_tracker_js_1 = require("./promise_combinator_tracker.js");
|
|
47
|
-
const javascript_pb_js_1 = require("./generated/proto/javascript_pb.js");
|
|
48
|
-
const node_buffer_1 = require("node:buffer");
|
|
49
|
-
class StateMachine {
|
|
50
|
-
connection;
|
|
51
|
-
invocation;
|
|
52
|
-
suspensionMillis;
|
|
53
|
-
journal;
|
|
54
|
-
restateContext;
|
|
55
|
-
invocationComplete = new promises_js_1.CompletablePromise();
|
|
56
|
-
// when this flag is true, no more work will (and may) happen
|
|
57
|
-
// this is set to true in case of
|
|
58
|
-
// - a completed invocation
|
|
59
|
-
// - a suspension
|
|
60
|
-
// - an error in the state machine
|
|
61
|
-
stateMachineClosed = false;
|
|
62
|
-
localStateStore;
|
|
63
|
-
// Whether the input channel (runtime -> service) is closed
|
|
64
|
-
// If it is closed, then we suspend immediately upon the next suspension point
|
|
65
|
-
// If it is open, then we suspend later because we might still get completions
|
|
66
|
-
inputChannelClosed = false;
|
|
67
|
-
// Suspension timeout that gets set and cleared based on completion messages;
|
|
68
|
-
suspensionTimeout;
|
|
69
|
-
promiseCombinatorTracker;
|
|
70
|
-
console;
|
|
71
|
-
constructor(connection, invocation, handlerKind, logger, loggerContext, extraArgs, suspensionMillis = 30_000) {
|
|
72
|
-
this.connection = connection;
|
|
73
|
-
this.invocation = invocation;
|
|
74
|
-
this.suspensionMillis = suspensionMillis;
|
|
75
|
-
this.localStateStore = invocation.localStateStore;
|
|
76
|
-
this.console = (0, message_logger_js_1.createStateMachineConsole)(logger, loggerContext);
|
|
77
|
-
this.journal = new journal_js_1.Journal(this.invocation);
|
|
78
|
-
this.restateContext = new context_impl_js_1.ContextImpl(this.invocation.id,
|
|
79
|
-
// The console exposed by RestateContext filters logs in replay, while the internal one is based on the ENV variables.
|
|
80
|
-
(0, logger_js_1.createRestateConsole)(logger, logger_js_1.LogSource.USER, loggerContext, this.journal.nextEntryWillBeReplayed.bind(this.journal)), handlerKind, invocation.userKey, invocation.invocationValue, invocation.invocationHeaders, connection.headers(), extraArgs, this);
|
|
81
|
-
this.promiseCombinatorTracker = new promise_combinator_tracker_js_1.PromiseCombinatorTracker(this.readCombinatorOrderEntry.bind(this), this.writeCombinatorOrderEntry.bind(this));
|
|
82
|
-
}
|
|
83
|
-
handleMessage(m) {
|
|
84
|
-
if (this.stateMachineClosed) {
|
|
85
|
-
// ignore this message
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
if (m.messageType === protocol_js_1.COMPLETION_MESSAGE_TYPE) {
|
|
89
|
-
this.console.debugJournalMessage("Received completion message from Restate, adding to journal.", m.messageType, m.message);
|
|
90
|
-
this.journal.handleRuntimeCompletionMessage(m.message);
|
|
91
|
-
}
|
|
92
|
-
else if (m.messageType === protocol_js_1.ENTRY_ACK_MESSAGE_TYPE) {
|
|
93
|
-
this.console.debugJournalMessage("Received entry ack message from Restate, adding to journal.", m.messageType, m.message);
|
|
94
|
-
this.journal.handleEntryAckMessage(m.message);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
throw errors_js_1.RetryableError.protocolViolation(`Received message of type ${m.messageType}. Can only accept completion or acks messages after replay has finished.`);
|
|
98
|
-
}
|
|
99
|
-
// Remove lingering suspension timeouts, if we are not waiting for completions anymore
|
|
100
|
-
if (this.suspensionTimeout !== undefined &&
|
|
101
|
-
this.journal.getCompletableIndices().length === 0) {
|
|
102
|
-
clearTimeout(this.suspensionTimeout);
|
|
103
|
-
this.suspensionTimeout = undefined;
|
|
104
|
-
}
|
|
105
|
-
return false; // we are never complete
|
|
106
|
-
}
|
|
107
|
-
handleUserCodeMessage(messageType, message, completedFlag, requiresAckFlag) {
|
|
108
|
-
// if the state machine is already closed, return a promise that never
|
|
109
|
-
// completes, so that the user code does not resume
|
|
110
|
-
if (this.stateMachineClosed) {
|
|
111
|
-
return promises_js_1.WRAPPED_PROMISE_PENDING;
|
|
112
|
-
}
|
|
113
|
-
const promise = this.journal.handleUserSideMessage(messageType, message);
|
|
114
|
-
const journalIndex = this.journal.getUserCodeJournalIndex();
|
|
115
|
-
// Only send the message to restate if we are not in replaying mode
|
|
116
|
-
if (this.journal.isProcessing()) {
|
|
117
|
-
this.console.debugJournalMessage("Adding message to journal and sending to Restate", messageType, message);
|
|
118
|
-
this.send(new types_js_1.Message(messageType, message, completedFlag, requiresAckFlag));
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
this.console.debugJournalMessage("Matched and replayed message from journal", messageType, message);
|
|
122
|
-
}
|
|
123
|
-
return (0, promises_js_1.wrapDeeply)(promise, () => {
|
|
124
|
-
if (!p.SUSPENSION_TRIGGERS.includes(messageType)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (this.journal.isUnResolved(journalIndex)) {
|
|
128
|
-
this.hitSuspensionPoint();
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
// -- Methods related to combinators to wire up promise combinator API with PromiseCombinatorTracker
|
|
133
|
-
createCombinator(combinatorConstructor, promises) {
|
|
134
|
-
if (this.stateMachineClosed) {
|
|
135
|
-
return promises_js_1.WRAPPED_PROMISE_PENDING;
|
|
136
|
-
}
|
|
137
|
-
// We don't need the promise wrapping here to schedule a suspension,
|
|
138
|
-
// because the combined promises will already have that, so once we call then() on them,
|
|
139
|
-
// if we have to suspend we will suspend.
|
|
140
|
-
return this.promiseCombinatorTracker.createCombinator(combinatorConstructor, promises);
|
|
141
|
-
}
|
|
142
|
-
readCombinatorOrderEntry(combinatorId) {
|
|
143
|
-
const wannabeCombinatorEntry = this.journal.readNextReplayEntry();
|
|
144
|
-
if (wannabeCombinatorEntry === undefined) {
|
|
145
|
-
// We're in processing mode
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
148
|
-
if (wannabeCombinatorEntry.messageType !== protocol_js_1.COMBINATOR_ENTRY_MESSAGE) {
|
|
149
|
-
throw errors_js_1.RetryableError.journalMismatch(this.journal.getUserCodeJournalIndex(), wannabeCombinatorEntry, {
|
|
150
|
-
messageType: protocol_js_1.COMBINATOR_ENTRY_MESSAGE,
|
|
151
|
-
message: {
|
|
152
|
-
combinatorId,
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
const combinatorMessage = wannabeCombinatorEntry.message;
|
|
157
|
-
if (combinatorMessage.combinatorId != combinatorId) {
|
|
158
|
-
throw errors_js_1.RetryableError.journalMismatch(this.journal.getUserCodeJournalIndex(), wannabeCombinatorEntry, {
|
|
159
|
-
messageType: protocol_js_1.COMBINATOR_ENTRY_MESSAGE,
|
|
160
|
-
message: {
|
|
161
|
-
combinatorId,
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
this.console.debugJournalMessage("Matched and replayed message from journal", protocol_js_1.COMBINATOR_ENTRY_MESSAGE, combinatorMessage);
|
|
166
|
-
return combinatorMessage.journalEntriesOrder.map((id) => ({
|
|
167
|
-
id,
|
|
168
|
-
type: promise_combinator_tracker_js_1.PromiseType.JournalEntry,
|
|
169
|
-
}));
|
|
170
|
-
}
|
|
171
|
-
async writeCombinatorOrderEntry(combinatorId, order) {
|
|
172
|
-
if (this.journal.isProcessing()) {
|
|
173
|
-
const combinatorMessage = new javascript_pb_js_1.CombinatorEntryMessage({
|
|
174
|
-
combinatorId,
|
|
175
|
-
journalEntriesOrder: order.map((pid) => pid.id),
|
|
176
|
-
});
|
|
177
|
-
this.console.debugJournalMessage("Adding message to journal and sending to Restate", protocol_js_1.COMBINATOR_ENTRY_MESSAGE, combinatorMessage);
|
|
178
|
-
const ackPromise = this.journal.appendJournalEntry(protocol_js_1.COMBINATOR_ENTRY_MESSAGE, combinatorMessage);
|
|
179
|
-
this.send(new types_js_1.Message(protocol_js_1.COMBINATOR_ENTRY_MESSAGE, combinatorMessage, undefined, true));
|
|
180
|
-
this.hitSuspensionPoint();
|
|
181
|
-
await ackPromise;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Invokes the RPC function and returns a promise that completes when the state machine
|
|
186
|
-
* stops processing the invocation, meaning when:
|
|
187
|
-
* - The function completes with a result or an exception
|
|
188
|
-
* - The execution suspends
|
|
189
|
-
* - An error is raised in the state machine (network, API violation, ...)
|
|
190
|
-
*
|
|
191
|
-
* The returned promise resolves successfully for all the cases above, because the are (from
|
|
192
|
-
* the perspective of the state machine) expected outcomes in which it send out corresponding
|
|
193
|
-
* result messages and cleanly closed the connection.
|
|
194
|
-
*
|
|
195
|
-
* The returned promise is rejected when an unhandled error arises and the caller would be
|
|
196
|
-
* expected to ensure that resources are properly cleaned up.
|
|
197
|
-
*/
|
|
198
|
-
invoke() {
|
|
199
|
-
// --------------------------------------------------------------------------------------------
|
|
200
|
-
// Implementation note:
|
|
201
|
-
//
|
|
202
|
-
// This method is not async, because we don't want to actually await anything
|
|
203
|
-
// in there. We cannot await the completion of the actual invocation, because for long-running
|
|
204
|
-
// code (that suspends), the function invocation never completes. Instead, the state machine
|
|
205
|
-
// triggers a suspension.
|
|
206
|
-
// We need to do a bit of promise chaining for the rpc function promise, and return a different
|
|
207
|
-
// promise that completes in also in suspension and error cases.
|
|
208
|
-
// --------------------------------------------------------------------------------------------
|
|
209
|
-
// it is unexpected for the state machine to be closed here, so we raise an error in
|
|
210
|
-
// that case, unlike in other places, where we simply ignore things
|
|
211
|
-
if (this.stateMachineClosed) {
|
|
212
|
-
return Promise.reject(new Error("state machine is already closed"));
|
|
213
|
-
}
|
|
214
|
-
if (this.journal.nextEntryWillBeReplayed()) {
|
|
215
|
-
this.console.info("Resuming (replaying) function.");
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
this.console.info("Invoking function.");
|
|
219
|
-
}
|
|
220
|
-
this.invocation.handler
|
|
221
|
-
.invoke(this.restateContext, this.invocation.invocationValue)
|
|
222
|
-
.then((bytes) => {
|
|
223
|
-
// invocation successfully returned with a result value
|
|
224
|
-
try {
|
|
225
|
-
// the state machine might be closed here in some cases like when there was an error (like
|
|
226
|
-
// API violation) or a suspension, but the function code still completed
|
|
227
|
-
if (this.stateMachineClosed) {
|
|
228
|
-
this.console.warn("Unexpected successful completion of the function after the state machine closed. " +
|
|
229
|
-
"This may indicate that: \n" +
|
|
230
|
-
"- the function code does not properly await some Restate calls " +
|
|
231
|
-
"and did not notice an error \n" +
|
|
232
|
-
"- the function code was delayed for longer than the suspension timeout \n" +
|
|
233
|
-
"- the function code contained a try-catch block around a side effect which throws retryable errors. " +
|
|
234
|
-
"This try-catch block should be placed inside the side effect.");
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
const value = node_buffer_1.Buffer.from(bytes);
|
|
238
|
-
// handle the result value
|
|
239
|
-
const msg = new types_js_1.Message(protocol_js_1.OUTPUT_ENTRY_MESSAGE_TYPE, new protocol_js_1.OutputEntryMessage({
|
|
240
|
-
result: { case: "value", value },
|
|
241
|
-
}));
|
|
242
|
-
void this.journal.handleUserSideMessage(msg.messageType, msg.message);
|
|
243
|
-
if (!this.journal.outputMsgWasReplayed()) {
|
|
244
|
-
this.send(msg);
|
|
245
|
-
this.console.debugJournalMessage("Journaled and sent output message", msg.messageType, msg.message);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
this.console.debugJournalMessage("Replayed and matched output message from journal", msg.messageType, msg.message);
|
|
249
|
-
}
|
|
250
|
-
this.console.info("Function completed successfully.");
|
|
251
|
-
// Mark the end of the invocation
|
|
252
|
-
this.send(new types_js_1.Message(protocol_js_1.END_MESSAGE_TYPE, new protocol_js_1.EndMessage()));
|
|
253
|
-
void this.finish(value);
|
|
254
|
-
}
|
|
255
|
-
catch (e) {
|
|
256
|
-
this.unhandledError((0, errors_js_1.ensureError)(e));
|
|
257
|
-
}
|
|
258
|
-
})
|
|
259
|
-
.catch((e) => {
|
|
260
|
-
// because of how we try/catch in the promise handler above, this here exclusively handles
|
|
261
|
-
// errors coming from the rpc function
|
|
262
|
-
try {
|
|
263
|
-
// Sometimes the function code fails as a consequence of the state machine encountering
|
|
264
|
-
// an error before (possibly Restate closed the connection).
|
|
265
|
-
if (this.stateMachineClosed) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
void this.sendErrorAndFinish((0, errors_js_1.ensureError)(e));
|
|
269
|
-
}
|
|
270
|
-
catch (ee) {
|
|
271
|
-
this.unhandledError((0, errors_js_1.ensureError)(ee));
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
// this promise here completes under any completion, including the cases where the
|
|
275
|
-
// rpc function does not end (error, suspension, ...)
|
|
276
|
-
return this.invocationComplete.promise;
|
|
277
|
-
}
|
|
278
|
-
async sendErrorAndFinish(e, ctx) {
|
|
279
|
-
this.console.warn("Function completed with an error.\n", e);
|
|
280
|
-
if (e instanceof errors_js_1.TerminalError) {
|
|
281
|
-
this.sendTerminalError(e);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
this.sendRetryableError(e, ctx);
|
|
285
|
-
}
|
|
286
|
-
await this.finish();
|
|
287
|
-
}
|
|
288
|
-
sendRetryableError(e, ctx) {
|
|
289
|
-
const msg = new types_js_1.Message(protocol_js_1.ERROR_MESSAGE_TYPE, (0, errors_js_1.errorToErrorMessage)(e, ctx));
|
|
290
|
-
this.console.debugJournalMessage("Invocation ended with retryable error.", msg.messageType, msg.message);
|
|
291
|
-
this.send(msg);
|
|
292
|
-
}
|
|
293
|
-
sendTerminalError(e) {
|
|
294
|
-
const msg = new types_js_1.Message(protocol_js_1.OUTPUT_ENTRY_MESSAGE_TYPE, new protocol_js_1.OutputEntryMessage({
|
|
295
|
-
result: { case: "failure", value: e.toFailure() },
|
|
296
|
-
}));
|
|
297
|
-
this.console.debugJournalMessage("Invocation ended with failure message.", msg.messageType, msg.message);
|
|
298
|
-
void this.journal.handleUserSideMessage(msg.messageType, msg.message);
|
|
299
|
-
if (!this.journal.outputMsgWasReplayed()) {
|
|
300
|
-
this.send(msg);
|
|
301
|
-
}
|
|
302
|
-
// Mark the end of the invocation
|
|
303
|
-
this.send(new types_js_1.Message(protocol_js_1.END_MESSAGE_TYPE, new protocol_js_1.EndMessage()));
|
|
304
|
-
}
|
|
305
|
-
send(message) {
|
|
306
|
-
this.connection.send(message).catch((err) => {
|
|
307
|
-
this.handleStreamError(err);
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Closes the state machine, flushes all output, and resolves the invocation promise.
|
|
312
|
-
*/
|
|
313
|
-
async finish(value) {
|
|
314
|
-
try {
|
|
315
|
-
this.stateMachineClosed = true;
|
|
316
|
-
this.journal.close();
|
|
317
|
-
this.clearSuspensionTimeout();
|
|
318
|
-
await this.connection.end();
|
|
319
|
-
this.invocationComplete.resolve(value);
|
|
320
|
-
}
|
|
321
|
-
catch (e) {
|
|
322
|
-
this.invocationComplete.reject((0, errors_js_1.ensureError)(e));
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* This function propagates errors up to the completion promise, to be handled
|
|
327
|
-
* on the connection layer.
|
|
328
|
-
*/
|
|
329
|
-
unhandledError(e) {
|
|
330
|
-
this.invocationComplete.reject(e);
|
|
331
|
-
this.stateMachineClosed = true;
|
|
332
|
-
this.journal.close();
|
|
333
|
-
this.clearSuspensionTimeout();
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* This method is invoked when we hit a suspension point. A suspension point is everytime the user "await"s a Promise returned by RestateContext that might be completed at a later point in time by a CompletionMessage/AckMessage.
|
|
337
|
-
*
|
|
338
|
-
* Depending on the state of the read channel, it might either immediately suspend, or schedule a suspension to happen at a later point in time.
|
|
339
|
-
*/
|
|
340
|
-
hitSuspensionPoint() {
|
|
341
|
-
// If there was already a timeout set, we want to reset the time to postpone suspension as long as we make progress.
|
|
342
|
-
// So we first clear the old timeout, and then we set a new one.
|
|
343
|
-
this.clearSuspensionTimeout();
|
|
344
|
-
const delay = this.getSuspensionMillis();
|
|
345
|
-
this.console.debugJournalMessage("Scheduling suspension in " + delay + " ms");
|
|
346
|
-
if (delay >= 0) {
|
|
347
|
-
// Set a new suspension with a new timeout
|
|
348
|
-
// The suspension will only be sent if the timeout is not canceled due to a completion.
|
|
349
|
-
// In case the delay is 0 we still schedule a timeout in order to process the suspension on the next process tick,
|
|
350
|
-
// without interrupting the current work.
|
|
351
|
-
this.suspensionTimeout = setTimeout(() => {
|
|
352
|
-
void this.suspend();
|
|
353
|
-
}, delay);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
// Suspension timeouts:
|
|
357
|
-
// - suspend after 30 seconds if input channel is still open (can still get completions)
|
|
358
|
-
// - suspend immediately if input channel is closed (cannot get completions)
|
|
359
|
-
getSuspensionMillis() {
|
|
360
|
-
return this.inputChannelClosed ? 0 : this.suspensionMillis;
|
|
361
|
-
}
|
|
362
|
-
async suspend() {
|
|
363
|
-
const indices = this.journal.getCompletableIndices();
|
|
364
|
-
// If the state is closed then we either already send a suspension
|
|
365
|
-
// or something else bad happened...
|
|
366
|
-
if (this.journal.isClosed() || indices.length === 0) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
// There need to be journal entries to complete, otherwise this timeout should have been removed.
|
|
370
|
-
// A suspension message is the end of the invocation.
|
|
371
|
-
// Resolve the root call with the suspension message
|
|
372
|
-
// This will lead to a onCallSuccess call where this msg will be sent.
|
|
373
|
-
const msg = new types_js_1.Message(protocol_js_1.SUSPENSION_MESSAGE_TYPE, new protocol_js_1.SuspensionMessage({
|
|
374
|
-
entryIndexes: indices,
|
|
375
|
-
}));
|
|
376
|
-
this.console.debugJournalMessage("Writing suspension message to journal.", msg.messageType, msg.message);
|
|
377
|
-
void this.journal.handleUserSideMessage(msg.messageType, msg.message);
|
|
378
|
-
if (!this.journal.outputMsgWasReplayed()) {
|
|
379
|
-
this.send(msg);
|
|
380
|
-
}
|
|
381
|
-
this.console.info("Suspending function.");
|
|
382
|
-
await this.finish();
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* WARNING: make sure you use this at the right point in the code
|
|
386
|
-
* After the index has been incremented...
|
|
387
|
-
* This is error-prone... Would be good to have a better solution for this.
|
|
388
|
-
*/
|
|
389
|
-
getUserCodeJournalIndex() {
|
|
390
|
-
return this.journal.getUserCodeJournalIndex();
|
|
391
|
-
}
|
|
392
|
-
handleInputClosed() {
|
|
393
|
-
if (this.journal.isClosed() ||
|
|
394
|
-
this.stateMachineClosed ||
|
|
395
|
-
this.inputChannelClosed) {
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
this.inputChannelClosed = true;
|
|
399
|
-
this.console.debug("Restate closed connection to trigger suspension.");
|
|
400
|
-
// If there is a timeout planned, reset the timout to execute immediately when the work is done.
|
|
401
|
-
if (this.suspensionTimeout !== undefined) {
|
|
402
|
-
this.hitSuspensionPoint();
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
handleStreamError(e) {
|
|
406
|
-
this.console.info("Aborting function execution and closing state machine due to connection error: " +
|
|
407
|
-
e.message);
|
|
408
|
-
this.unhandledError(e);
|
|
409
|
-
}
|
|
410
|
-
handleDanglingPromiseError(e) {
|
|
411
|
-
this.console.info("Aborting function execution and closing state machine due to an error: " +
|
|
412
|
-
e.message);
|
|
413
|
-
this.unhandledError(e);
|
|
414
|
-
}
|
|
415
|
-
nextEntryWillBeReplayed() {
|
|
416
|
-
return this.journal.nextEntryWillBeReplayed();
|
|
417
|
-
}
|
|
418
|
-
clearSuspensionTimeout() {
|
|
419
|
-
if (this.suspensionTimeout !== undefined) {
|
|
420
|
-
clearTimeout(this.suspensionTimeout);
|
|
421
|
-
this.suspensionTimeout = undefined;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
exports.StateMachine = StateMachine;
|
|
426
|
-
//# sourceMappingURL=state_machine.js.map
|