@temporalio/core-bridge 1.5.2 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/Cargo.lock +304 -112
  2. package/lib/index.d.ts +8 -6
  3. package/lib/index.js.map +1 -1
  4. package/package.json +9 -4
  5. package/releases/aarch64-apple-darwin/index.node +0 -0
  6. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  7. package/releases/x86_64-apple-darwin/index.node +0 -0
  8. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  9. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  10. package/sdk-core/.buildkite/docker/Dockerfile +2 -2
  11. package/sdk-core/.buildkite/docker/docker-compose.yaml +1 -1
  12. package/sdk-core/.buildkite/pipeline.yml +2 -4
  13. package/sdk-core/.cargo/config.toml +5 -2
  14. package/sdk-core/.github/workflows/heavy.yml +29 -0
  15. package/sdk-core/Cargo.toml +1 -1
  16. package/sdk-core/README.md +20 -10
  17. package/sdk-core/client/src/lib.rs +215 -39
  18. package/sdk-core/client/src/metrics.rs +17 -8
  19. package/sdk-core/client/src/raw.rs +4 -4
  20. package/sdk-core/client/src/retry.rs +32 -20
  21. package/sdk-core/core/Cargo.toml +25 -12
  22. package/sdk-core/core/src/abstractions/take_cell.rs +28 -0
  23. package/sdk-core/core/src/abstractions.rs +204 -14
  24. package/sdk-core/core/src/core_tests/activity_tasks.rs +143 -50
  25. package/sdk-core/core/src/core_tests/child_workflows.rs +6 -5
  26. package/sdk-core/core/src/core_tests/determinism.rs +165 -2
  27. package/sdk-core/core/src/core_tests/local_activities.rs +431 -43
  28. package/sdk-core/core/src/core_tests/queries.rs +34 -16
  29. package/sdk-core/core/src/core_tests/workers.rs +8 -5
  30. package/sdk-core/core/src/core_tests/workflow_tasks.rs +588 -55
  31. package/sdk-core/core/src/ephemeral_server/mod.rs +113 -12
  32. package/sdk-core/core/src/internal_flags.rs +155 -0
  33. package/sdk-core/core/src/lib.rs +16 -9
  34. package/sdk-core/core/src/protosext/mod.rs +1 -1
  35. package/sdk-core/core/src/replay/mod.rs +16 -27
  36. package/sdk-core/core/src/telemetry/log_export.rs +1 -1
  37. package/sdk-core/core/src/telemetry/metrics.rs +69 -35
  38. package/sdk-core/core/src/telemetry/mod.rs +60 -21
  39. package/sdk-core/core/src/telemetry/prometheus_server.rs +19 -13
  40. package/sdk-core/core/src/test_help/mod.rs +73 -14
  41. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +119 -160
  42. package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
  43. package/sdk-core/core/src/worker/activities/local_activities.rs +379 -129
  44. package/sdk-core/core/src/worker/activities.rs +350 -175
  45. package/sdk-core/core/src/worker/client/mocks.rs +22 -2
  46. package/sdk-core/core/src/worker/client.rs +18 -2
  47. package/sdk-core/core/src/worker/mod.rs +183 -64
  48. package/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
  49. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +3 -5
  50. package/sdk-core/core/src/worker/workflow/history_update.rs +916 -277
  51. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +216 -183
  52. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +9 -12
  53. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +7 -9
  54. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +160 -87
  55. package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +13 -14
  56. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -9
  57. package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +14 -17
  58. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +242 -110
  59. package/sdk-core/core/src/worker/workflow/machines/mod.rs +27 -19
  60. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +9 -11
  61. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +321 -206
  62. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +13 -18
  63. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +20 -29
  64. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +2 -2
  65. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +257 -51
  66. package/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
  67. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +310 -150
  68. package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +17 -20
  69. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +31 -15
  70. package/sdk-core/core/src/worker/workflow/managed_run.rs +1052 -380
  71. package/sdk-core/core/src/worker/workflow/mod.rs +598 -390
  72. package/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
  73. package/sdk-core/core/src/worker/workflow/wft_extraction.rs +137 -0
  74. package/sdk-core/core/src/worker/workflow/wft_poller.rs +1 -4
  75. package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
  76. package/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
  77. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +469 -718
  78. package/sdk-core/core-api/Cargo.toml +2 -1
  79. package/sdk-core/core-api/src/errors.rs +1 -34
  80. package/sdk-core/core-api/src/lib.rs +19 -9
  81. package/sdk-core/core-api/src/telemetry.rs +4 -6
  82. package/sdk-core/core-api/src/worker.rs +19 -1
  83. package/sdk-core/etc/deps.svg +115 -140
  84. package/sdk-core/etc/regen-depgraph.sh +5 -0
  85. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +86 -61
  86. package/sdk-core/fsm/rustfsm_trait/src/lib.rs +29 -71
  87. package/sdk-core/histories/ends_empty_wft_complete.bin +0 -0
  88. package/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
  89. package/sdk-core/histories/old_change_marker_format.bin +0 -0
  90. package/sdk-core/protos/api_upstream/.github/CODEOWNERS +2 -1
  91. package/sdk-core/protos/api_upstream/Makefile +6 -6
  92. package/sdk-core/protos/api_upstream/build/go.mod +7 -0
  93. package/sdk-core/protos/api_upstream/build/go.sum +5 -0
  94. package/sdk-core/protos/api_upstream/build/tools.go +29 -0
  95. package/sdk-core/protos/api_upstream/go.mod +6 -0
  96. package/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +9 -2
  97. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +7 -26
  98. package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
  99. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  100. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +3 -7
  101. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  102. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +8 -8
  103. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +25 -2
  104. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  105. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  106. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  107. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  108. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  109. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +24 -19
  110. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  111. package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  112. package/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  113. package/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  114. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +49 -26
  115. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
  116. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +5 -2
  117. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -2
  118. package/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +57 -0
  119. package/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  120. package/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  121. package/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +2 -2
  122. package/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
  123. package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -2
  124. package/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
  125. package/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  126. package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +2 -2
  127. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +64 -28
  128. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +4 -4
  129. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +7 -8
  130. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +10 -7
  131. package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +19 -30
  132. package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
  133. package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
  134. package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +8 -0
  135. package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +67 -60
  136. package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +85 -84
  137. package/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +9 -3
  138. package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  139. package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  140. package/sdk-core/sdk/Cargo.toml +5 -4
  141. package/sdk-core/sdk/src/lib.rs +108 -26
  142. package/sdk-core/sdk/src/workflow_context/options.rs +7 -1
  143. package/sdk-core/sdk/src/workflow_context.rs +24 -17
  144. package/sdk-core/sdk/src/workflow_future.rs +16 -15
  145. package/sdk-core/sdk-core-protos/Cargo.toml +5 -2
  146. package/sdk-core/sdk-core-protos/build.rs +36 -2
  147. package/sdk-core/sdk-core-protos/src/history_builder.rs +138 -106
  148. package/sdk-core/sdk-core-protos/src/history_info.rs +10 -1
  149. package/sdk-core/sdk-core-protos/src/lib.rs +272 -87
  150. package/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
  151. package/sdk-core/test-utils/Cargo.toml +3 -1
  152. package/sdk-core/test-utils/src/canned_histories.rs +106 -296
  153. package/sdk-core/test-utils/src/histfetch.rs +1 -1
  154. package/sdk-core/test-utils/src/lib.rs +82 -23
  155. package/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
  156. package/sdk-core/test-utils/src/workflows.rs +29 -0
  157. package/sdk-core/tests/fuzzy_workflow.rs +130 -0
  158. package/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
  159. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
  160. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
  161. package/sdk-core/tests/integ_tests/metrics_tests.rs +218 -16
  162. package/sdk-core/tests/integ_tests/polling_tests.rs +4 -47
  163. package/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
  164. package/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
  165. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +161 -72
  166. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
  167. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
  168. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +80 -3
  169. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
  170. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
  171. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +94 -200
  172. package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +2 -4
  173. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +34 -28
  174. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +76 -7
  175. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
  176. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
  177. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
  178. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
  179. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +7 -8
  180. package/sdk-core/tests/integ_tests/workflow_tests.rs +13 -14
  181. package/sdk-core/tests/main.rs +3 -13
  182. package/sdk-core/tests/runner.rs +75 -36
  183. package/sdk-core/tests/wf_input_replay.rs +32 -0
  184. package/src/conversions.rs +14 -8
  185. package/src/runtime.rs +9 -8
  186. package/ts/index.ts +8 -6
  187. package/sdk-core/bridge-ffi/Cargo.toml +0 -24
  188. package/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  189. package/sdk-core/bridge-ffi/build.rs +0 -25
  190. package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -224
  191. package/sdk-core/bridge-ffi/src/lib.rs +0 -746
  192. package/sdk-core/bridge-ffi/src/wrappers.rs +0 -221
  193. package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  194. package/sdk-core/sdk/src/conversions.rs +0 -8
@@ -64,21 +64,21 @@ use syn::{
64
64
  /// }
65
65
  ///
66
66
  /// impl Locked {
67
- /// fn on_card_readable(&self, shared_dat: SharedState, data: CardData)
67
+ /// fn on_card_readable(&self, shared_dat: &mut SharedState, data: CardData)
68
68
  /// -> CardReaderTransition<ReadingCardOrLocked> {
69
- /// match shared_dat.last_id {
69
+ /// match &shared_dat.last_id {
70
70
  /// // Arbitrarily deny the same person entering twice in a row
71
- /// Some(d) if d == data => TransitionResult::ok(vec![], Locked {}.into()),
71
+ /// Some(d) if d == &data => TransitionResult::ok(vec![], Locked {}.into()),
72
72
  /// _ => {
73
73
  /// // Otherwise issue a processing command. This illustrates using the same handler
74
74
  /// // for different destinations
75
- /// TransitionResult::ok_shared(
75
+ /// shared_dat.last_id = Some(data.clone());
76
+ /// TransitionResult::ok(
76
77
  /// vec![
77
78
  /// Commands::ProcessData(data.clone()),
78
79
  /// Commands::StartBlinkingLight,
79
80
  /// ],
80
- /// ReadingCard { card_data: data.clone() }.into(),
81
- /// SharedState { last_id: Some(data) }
81
+ /// ReadingCard { card_data: data }.into(),
82
82
  /// )
83
83
  /// }
84
84
  /// }
@@ -96,19 +96,19 @@ use syn::{
96
96
  ///
97
97
  /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
98
98
  /// let crs = CardReaderState::Locked(Locked {});
99
- /// let mut cr = CardReader { state: crs, shared_state: SharedState { last_id: None } };
100
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardReadable("badguy".to_string()))?;
99
+ /// let mut cr = CardReader::from_parts(crs, SharedState { last_id: None });
100
+ /// let cmds = cr.on_event(CardReaderEvents::CardReadable("badguy".to_string()))?;
101
101
  /// assert_eq!(cmds[0], Commands::ProcessData("badguy".to_string()));
102
102
  /// assert_eq!(cmds[1], Commands::StartBlinkingLight);
103
103
  ///
104
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardRejected)?;
104
+ /// let cmds = cr.on_event(CardReaderEvents::CardRejected)?;
105
105
  /// assert_eq!(cmds[0], Commands::StopBlinkingLight);
106
106
  ///
107
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardReadable("goodguy".to_string()))?;
107
+ /// let cmds = cr.on_event(CardReaderEvents::CardReadable("goodguy".to_string()))?;
108
108
  /// assert_eq!(cmds[0], Commands::ProcessData("goodguy".to_string()));
109
109
  /// assert_eq!(cmds[1], Commands::StartBlinkingLight);
110
110
  ///
111
- /// let cmds = cr.on_event_mut(CardReaderEvents::CardAccepted)?;
111
+ /// let cmds = cr.on_event(CardReaderEvents::CardAccepted)?;
112
112
  /// assert_eq!(cmds[0], Commands::StopBlinkingLight);
113
113
  /// # Ok(())
114
114
  /// # }
@@ -132,17 +132,17 @@ use syn::{
132
132
  /// The macro will generate a few things:
133
133
  /// * A struct for the overall state machine, named with the provided name. Here:
134
134
  /// ```text
135
- /// struct CardMachine {
136
- /// state: CardMachineState,
137
- /// shared_state: CardId,
135
+ /// struct CardReader {
136
+ /// state: CardReaderState,
137
+ /// shared_state: SharedState,
138
138
  /// }
139
139
  /// ```
140
140
  /// * An enum with a variant for each state, named with the provided name + "State".
141
141
  /// ```text
142
- /// enum CardMachineState {
142
+ /// enum CardReaderState {
143
143
  /// Locked(Locked),
144
144
  /// ReadingCard(ReadingCard),
145
- /// Unlocked(Unlocked),
145
+ /// DoorOpen(DoorOpen),
146
146
  /// }
147
147
  /// ```
148
148
  ///
@@ -154,15 +154,18 @@ use syn::{
154
154
  /// * An enum with a variant for each event. You are expected to define the type (if any) contained
155
155
  /// in the event variant.
156
156
  /// ```text
157
- /// enum CardMachineEvents {
158
- /// CardReadable(CardData)
157
+ /// enum CardReaderEvents {
158
+ /// DoorClosed,
159
+ /// CardAccepted,
160
+ /// CardRejected,
161
+ /// CardReadable(CardData),
159
162
  /// }
160
163
  /// ```
161
164
  /// * An implementation of the [StateMachine](trait.StateMachine.html) trait for the generated state
162
- /// machine enum (in this case, `CardMachine`)
165
+ /// machine enum (in this case, `CardReader`)
163
166
  /// * A type alias for a [TransitionResult](enum.TransitionResult.html) with the appropriate generic
164
167
  /// parameters set for your machine. It is named as your machine with `Transition` appended. In
165
- /// this case, `CardMachineTransition`.
168
+ /// this case, `CardReaderTransition`.
166
169
  #[proc_macro]
167
170
  pub fn fsm(input: TokenStream) -> TokenStream {
168
171
  let def: StateMachineDefinition = parse_macro_input!(input as StateMachineDefinition);
@@ -217,7 +220,7 @@ impl Parse for StateMachineDefinition {
217
220
  // not ideal.
218
221
  let trans_set: HashSet<_> = transitions.iter().collect();
219
222
  if trans_set.len() != transitions.len() {
220
- return Err(syn::Error::new(
223
+ return Err(Error::new(
221
224
  input.span(),
222
225
  "Duplicate transitions are not allowed!",
223
226
  ));
@@ -346,12 +349,12 @@ impl StateMachineDefinition {
346
349
  let name = &self.name;
347
350
  let name_str = &self.name.to_string();
348
351
 
349
- let transition_result_name = Ident::new(&format!("{}Transition", name), name.span());
352
+ let transition_result_name = Ident::new(&format!("{name}Transition"), name.span());
350
353
  let transition_type_alias = quote! {
351
354
  type #transition_result_name<Ds, Sm = #name> = TransitionResult<Sm, Ds>;
352
355
  };
353
356
 
354
- let state_enum_name = Ident::new(&format!("{}State", name), name.span());
357
+ let state_enum_name = Ident::new(&format!("{name}State"), name.span());
355
358
  // If user has not defined any shared state, use the unit type.
356
359
  let shared_state_type = self
357
360
  .shared_state_type
@@ -360,7 +363,7 @@ impl StateMachineDefinition {
360
363
  let machine_struct = quote! {
361
364
  #[derive(Clone)]
362
365
  #visibility struct #name {
363
- state: #state_enum_name,
366
+ state: ::core::option::Option<#state_enum_name>,
364
367
  shared_state: #shared_state_type
365
368
  }
366
369
  };
@@ -390,7 +393,7 @@ impl StateMachineDefinition {
390
393
 
391
394
  // Build the events enum
392
395
  let events: HashSet<Variant> = self.transitions.iter().map(|t| t.event.clone()).collect();
393
- let events_enum_name = Ident::new(&format!("{}Events", name), name.span());
396
+ let events_enum_name = Ident::new(&format!("{name}Events"), name.span());
394
397
  let events: Vec<_> = events
395
398
  .into_iter()
396
399
  .map(|v| {
@@ -424,8 +427,18 @@ impl StateMachineDefinition {
424
427
  statemap.insert(s.clone(), vec![]);
425
428
  }
426
429
  }
430
+ let transition_result_transform = quote! {
431
+ match res.into_cmd_result() {
432
+ Ok((cmds, state)) => {
433
+ self.state = Some(state);
434
+ Ok(cmds)
435
+ }
436
+ Err(e) => Err(e)
437
+ }
438
+ };
427
439
  let mut multi_dest_enums = vec![];
428
440
  let state_branches: Vec<_> = statemap.into_iter().map(|(from, transitions)| {
441
+ let occupied_current_state = quote! { Some(#state_enum_name::#from(state_data)) };
429
442
  // Merge transition dest states with the same handler
430
443
  let transitions = merge_transition_dests(transitions);
431
444
  let event_branches = transitions
@@ -467,27 +480,27 @@ impl StateMachineDefinition {
467
480
  match ts.event.fields {
468
481
  Fields::Unnamed(_) => {
469
482
  let arglist = if ts.mutates_shared {
470
- quote! {self.shared_state, val}
483
+ quote! {&mut self.shared_state, val}
471
484
  } else {
472
485
  quote! {val}
473
486
  };
474
- quote_spanned! {span=>
487
+ quote_spanned! { span =>
475
488
  #events_enum_name::#ev_variant(val) => {
476
489
  let res: #trans_type = state_data.#ts_fn(#arglist);
477
- res.into_general()
490
+ #transition_result_transform
478
491
  }
479
492
  }
480
493
  }
481
494
  Fields::Unit => {
482
495
  let arglist = if ts.mutates_shared {
483
- quote! {self.shared_state}
496
+ quote! {&mut self.shared_state}
484
497
  } else {
485
498
  quote! {}
486
499
  };
487
- quote_spanned! {span=>
500
+ quote_spanned! { span =>
488
501
  #events_enum_name::#ev_variant => {
489
502
  let res: #trans_type = state_data.#ts_fn(#arglist);
490
- res.into_general()
503
+ #transition_result_transform
491
504
  }
492
505
  }
493
506
  }
@@ -498,39 +511,49 @@ impl StateMachineDefinition {
498
511
  // using `Default`.
499
512
  if let [new_state] = ts.to.as_slice() {
500
513
  let span = new_state.span();
501
- let default_trans = quote_spanned! {span=>
502
- TransitionResult::<_, #new_state>::from::<#from>(state_data).into_general()
503
- };
514
+ let default_trans = quote_spanned! { span =>
515
+ let res = TransitionResult::<Self, #new_state>::from::<#from>(state_data);
516
+ #transition_result_transform
517
+ };
504
518
  let span = ts.event.span();
505
519
  match ts.event.fields {
506
- Fields::Unnamed(_) => quote_spanned! {span=>
507
- #events_enum_name::#ev_variant(_val) => {
508
- #default_trans
509
- }
510
- },
511
- Fields::Unit => quote_spanned! {span=>
512
- #events_enum_name::#ev_variant => {
513
- #default_trans
514
- }
515
- },
520
+ Fields::Unnamed(_) => quote_spanned! { span =>
521
+ #events_enum_name::#ev_variant(_val) => {
522
+ #default_trans
523
+ }
524
+ },
525
+ Fields::Unit => quote_spanned! { span =>
526
+ #events_enum_name::#ev_variant => {
527
+ #default_trans
528
+ }
529
+ },
516
530
  Fields::Named(_) => unreachable!(),
517
531
  }
518
-
519
532
  } else {
520
- unreachable!("It should be impossible to have more than one dest state in no-handler transitions")
533
+ unreachable!("It should be impossible to have more than one dest state \
534
+ in no-handler transitions")
521
535
  }
522
536
  }
523
537
  })
524
- // Since most states won't handle every possible event, return an error to that effect
538
+ // Since most states won't handle every possible event, return an error to that
539
+ // effect
525
540
  .chain(std::iter::once(
526
- quote! { _ => { return TransitionResult::InvalidTransition } },
541
+ quote! { _ => {
542
+ // Restore state in event the transition doesn't match
543
+ self.state = #occupied_current_state;
544
+ return Err(::rustfsm::MachineError::InvalidTransition)
545
+ } },
527
546
  ));
528
547
  quote! {
529
- #state_enum_name::#from(state_data) => match event {
548
+ #occupied_current_state => match event {
530
549
  #(#event_branches),*
531
550
  }
532
551
  }
533
- }).collect();
552
+ }).chain(std::iter::once(
553
+ quote! {
554
+ None => Err(::rustfsm::MachineError::InvalidTransition)
555
+ }
556
+ )).collect();
534
557
 
535
558
  let viz_str = self.visualize();
536
559
 
@@ -546,19 +569,21 @@ impl StateMachineDefinition {
546
569
  #name_str
547
570
  }
548
571
 
549
- fn on_event(self, event: #events_enum_name)
550
- -> ::rustfsm::TransitionResult<Self, Self::State> {
551
- match self.state {
572
+ fn on_event(&mut self, event: #events_enum_name)
573
+ -> ::core::result::Result<::std::vec::Vec<Self::Command>,
574
+ ::rustfsm::MachineError<Self::Error>> {
575
+ let taken_state = self.state.take();
576
+ match taken_state {
552
577
  #(#state_branches),*
553
578
  }
554
579
  }
555
580
 
556
581
  fn state(&self) -> &Self::State {
557
- &self.state
582
+ self.state.as_ref().unwrap()
558
583
  }
559
584
 
560
585
  fn set_state(&mut self, new: Self::State) {
561
- self.state = new
586
+ self.state = Some(new)
562
587
  }
563
588
 
564
589
  fn shared_state(&self) -> &Self::SharedState{
@@ -566,11 +591,11 @@ impl StateMachineDefinition {
566
591
  }
567
592
 
568
593
  fn has_reached_final_state(&self) -> bool {
569
- self.state.is_final()
594
+ self.state.as_ref().unwrap().is_final()
570
595
  }
571
596
 
572
- fn from_parts(shared: Self::SharedState, state: Self::State) -> Self {
573
- Self { shared_state: shared, state }
597
+ fn from_parts(state: Self::State, shared: Self::SharedState) -> Self {
598
+ Self { shared_state: shared, state: Some(state) }
574
599
  }
575
600
 
576
601
  fn visualizer() -> &'static str {
@@ -616,11 +641,11 @@ impl StateMachineDefinition {
616
641
  self.all_states()
617
642
  .iter()
618
643
  .filter(|s| self.is_final_state(s))
619
- .map(|s| format!("{} --> [*]", s)),
644
+ .map(|s| format!("{s} --> [*]")),
620
645
  )
621
646
  .collect();
622
647
  let transitions = transitions.join("\n");
623
- format!("@startuml\n{}\n@enduml", transitions)
648
+ format!("@startuml\n{transitions}\n@enduml")
624
649
  }
625
650
  }
626
651
 
@@ -643,5 +668,5 @@ fn merge_transition_dests(transitions: Vec<Transition>) -> Vec<Transition> {
643
668
  }
644
669
  }
645
670
  }
646
- map.into_iter().map(|(_, v)| v).collect()
671
+ map.into_values().collect()
647
672
  }
@@ -19,44 +19,12 @@ pub trait StateMachine: Sized {
19
19
  /// The type used to represent commands the machine issues upon transitions.
20
20
  type Command;
21
21
 
22
- /// Handle an incoming event, returning a transition result which represents updates to apply
23
- /// to the state machine.
24
- fn on_event(self, event: Self::Event) -> TransitionResult<Self, Self::State>;
25
-
26
- /// Handle an incoming event and mutate the state machine to update to the new state and apply
27
- /// any changes to shared state.
28
- ///
29
- /// Returns the commands issued by the transition on success, otherwise a [MachineError]
30
- fn on_event_mut(
22
+ /// Handle an incoming event, returning any new commands or an error. Implementations may
23
+ /// mutate current state, possibly moving to a new state.
24
+ fn on_event(
31
25
  &mut self,
32
26
  event: Self::Event,
33
- ) -> Result<Vec<Self::Command>, MachineError<Self::Error>>
34
- where
35
- Self: Clone,
36
- {
37
- // NOTE: This clone is actually nice in some sense, giving us a kind of transactionality.
38
- // However if there are really big things in state it could be an issue.
39
- let res = self.clone().on_event(event);
40
- match res {
41
- TransitionResult::Ok {
42
- commands,
43
- new_state,
44
- shared_state,
45
- } => {
46
- *self = Self::from_parts(shared_state, new_state);
47
- Ok(commands)
48
- }
49
- TransitionResult::OkNoShare {
50
- commands,
51
- new_state,
52
- } => {
53
- self.set_state(new_state);
54
- Ok(commands)
55
- }
56
- TransitionResult::InvalidTransition => Err(MachineError::InvalidTransition),
57
- TransitionResult::Err(e) => Err(MachineError::Underlying(e)),
58
- }
59
- }
27
+ ) -> Result<Vec<Self::Command>, MachineError<Self::Error>>;
60
28
 
61
29
  fn name(&self) -> &str;
62
30
 
@@ -71,7 +39,7 @@ pub trait StateMachine: Sized {
71
39
  fn has_reached_final_state(&self) -> bool;
72
40
 
73
41
  /// Given the shared data and new state, create a new instance.
74
- fn from_parts(shared: Self::SharedState, state: Self::State) -> Self;
42
+ fn from_parts(state: Self::State, shared: Self::SharedState) -> Self;
75
43
 
76
44
  /// Return a PlantUML definition of the fsm that can be used to visualize it
77
45
  fn visualizer() -> &'static str;
@@ -136,12 +104,6 @@ where
136
104
  Ok {
137
105
  commands: Vec<Machine::Command>,
138
106
  new_state: DestinationState,
139
- shared_state: Machine::SharedState,
140
- },
141
- /// The transition was successful with no shared state change
142
- OkNoShare {
143
- commands: Vec<Machine::Command>,
144
- new_state: DestinationState,
145
107
  },
146
108
  /// There was some error performing the transition
147
109
  Err(Machine::Error),
@@ -157,24 +119,10 @@ where
157
119
  pub fn ok<CI>(commands: CI, new_state: Ds) -> Self
158
120
  where
159
121
  CI: IntoIterator<Item = Sm::Command>,
160
- {
161
- Self::OkNoShare {
162
- commands: commands.into_iter().collect(),
163
- new_state,
164
- }
165
- }
166
-
167
- /// Produce a transition with the provided commands to the provided state with shared state
168
- /// changes
169
- pub fn ok_shared<CI, SS>(commands: CI, new_state: Ds, new_shared: SS) -> Self
170
- where
171
- CI: IntoIterator<Item = Sm::Command>,
172
- SS: Into<Sm::SharedState>,
173
122
  {
174
123
  Self::Ok {
175
124
  commands: commands.into_iter().collect(),
176
125
  new_state,
177
- shared_state: new_shared.into(),
178
126
  }
179
127
  }
180
128
 
@@ -185,7 +133,7 @@ where
185
133
  CurrentState: Into<Ds>,
186
134
  {
187
135
  let as_dest: Ds = current_state.into();
188
- Self::OkNoShare {
136
+ Self::Ok {
189
137
  commands: vec![],
190
138
  new_state: as_dest,
191
139
  }
@@ -202,16 +150,20 @@ where
202
150
  where
203
151
  CI: IntoIterator<Item = Sm::Command>,
204
152
  {
205
- Self::OkNoShare {
153
+ Self::Ok {
206
154
  commands: commands.into_iter().collect(),
207
155
  new_state: Ds::default(),
208
156
  }
209
157
  }
158
+ }
210
159
 
211
- /// Produce a transition with no commands relying on [Default] for the destination state's
212
- /// value
213
- pub fn default() -> Self {
214
- Self::OkNoShare {
160
+ impl<Sm, Ds> Default for TransitionResult<Sm, Ds>
161
+ where
162
+ Sm: StateMachine,
163
+ Ds: Into<Sm::State> + Default,
164
+ {
165
+ fn default() -> Self {
166
+ Self::Ok {
215
167
  commands: vec![],
216
168
  new_state: Ds::default(),
217
169
  }
@@ -230,20 +182,26 @@ where
230
182
  TransitionResult::Ok {
231
183
  commands,
232
184
  new_state,
233
- shared_state,
234
185
  } => TransitionResult::Ok {
235
186
  commands,
236
187
  new_state: new_state.into(),
237
- shared_state,
238
188
  },
239
- TransitionResult::OkNoShare {
240
- commands,
189
+ TransitionResult::Err(e) => TransitionResult::Err(e),
190
+ }
191
+ }
192
+
193
+ /// Transforms the transition result into a machine-ready outcome with commands and new state,
194
+ /// or a [MachineError]
195
+ #[allow(clippy::type_complexity)]
196
+ pub fn into_cmd_result(self) -> Result<(Vec<Sm::Command>, Sm::State), MachineError<Sm::Error>> {
197
+ let general = self.into_general();
198
+ match general {
199
+ TransitionResult::Ok {
241
200
  new_state,
242
- } => TransitionResult::OkNoShare {
243
201
  commands,
244
- new_state: new_state.into(),
245
- },
246
- TransitionResult::Err(e) => TransitionResult::Err(e),
202
+ } => Ok((commands, new_state)),
203
+ TransitionResult::InvalidTransition => Err(MachineError::InvalidTransition),
204
+ TransitionResult::Err(e) => Err(MachineError::Underlying(e)),
247
205
  }
248
206
  }
249
207
  }
@@ -1,4 +1,5 @@
1
1
  # Syntax is here:
2
2
  # https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax
3
3
 
4
- * @temporalio/server @temporalio/sdk
4
+ * @temporalio/server @temporalio/sdk
5
+ api/temporal/api/sdk/* @temporalio/sdk
@@ -23,7 +23,7 @@ PROTO_ROOT := .
23
23
  PROTO_FILES = $(shell find $(PROTO_ROOT) -name "*.proto")
24
24
  PROTO_DIRS = $(sort $(dir $(PROTO_FILES)))
25
25
  PROTO_OUT := .gen
26
- PROTO_IMPORTS := -I=$(PROTO_ROOT) -I=$(GOPATH)/src/github.com/temporalio/gogo-protobuf/protobuf
26
+ PROTO_IMPORTS = -I=$(PROTO_ROOT) -I=$(shell go list -modfile build/go.mod -m -f '{{.Dir}}' github.com/temporalio/gogo-protobuf)/protobuf
27
27
 
28
28
  $(PROTO_OUT):
29
29
  mkdir $(PROTO_OUT)
@@ -37,7 +37,7 @@ go-grpc: clean $(PROTO_OUT)
37
37
 
38
38
  gogo-grpc: clean $(PROTO_OUT)
39
39
  printf $(COLOR) "Compile for gogo-gRPC..."
40
- $(foreach PROTO_DIR,$(PROTO_DIRS),protoc --fatal_warnings $(PROTO_IMPORTS) --gogoslick_out=Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT) $(PROTO_DIR)*.proto;)
40
+ $(foreach PROTO_DIR,$(PROTO_DIRS),protoc --fatal_warnings $(PROTO_IMPORTS) --gogoslick_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:$(PROTO_OUT) $(PROTO_DIR)*.proto;)
41
41
 
42
42
  fix-path:
43
43
  mv -f $(PROTO_OUT)/temporal/api/* $(PROTO_OUT) && rm -rf $(PROTO_OUT)/temporal
@@ -45,21 +45,21 @@ fix-path:
45
45
  ##### Plugins & tools #####
46
46
  grpc-install: gogo-protobuf-install
47
47
  printf $(COLOR) "Install/update gRPC plugins..."
48
- go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2.0
48
+ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
49
49
 
50
50
  gogo-protobuf-install: go-protobuf-install
51
- GO111MODULE=off go get github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick
51
+ go install -modfile build/go.mod github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick
52
52
 
53
53
  go-protobuf-install:
54
54
  go install github.com/golang/protobuf/protoc-gen-go@v1.5.2
55
55
 
56
56
  api-linter-install:
57
57
  printf $(COLOR) "Install/update api-linter..."
58
- go install github.com/googleapis/api-linter/cmd/api-linter@v1.31.0
58
+ go install github.com/googleapis/api-linter/cmd/api-linter@v1.32.3
59
59
 
60
60
  buf-install:
61
61
  printf $(COLOR) "Install/update buf..."
62
- go install github.com/bufbuild/buf/cmd/buf@v1.4.0
62
+ go install github.com/bufbuild/buf/cmd/buf@v1.6.0
63
63
 
64
64
  ##### Linters #####
65
65
  api-linter:
@@ -0,0 +1,7 @@
1
+ module build
2
+
3
+ go 1.18
4
+
5
+ require (
6
+ github.com/temporalio/gogo-protobuf v1.22.1
7
+ )
@@ -0,0 +1,5 @@
1
+ github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
2
+ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
3
+ github.com/temporalio/gogo-protobuf v1.22.1 h1:K5ja5MqmCQKo4tlX7u3g+ZJqbvRr0589ss2cZQx2dSM=
4
+ github.com/temporalio/gogo-protobuf v1.22.1/go.mod h1:tCaEv+fB8tsyLgoaqKr78K/JOhdRe684yyo0z30SHyA=
5
+ golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -0,0 +1,29 @@
1
+ // The MIT License
2
+ //
3
+ // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
4
+ //
5
+ // Copyright (c) 2020 Uber Technologies, Inc.
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in
15
+ // all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ // THE SOFTWARE.
24
+
25
+ package build
26
+
27
+ import (
28
+ _ "github.com/temporalio/gogo-protobuf/gogoproto" // gogoproto is just a random package name for module.
29
+ )
@@ -0,0 +1,6 @@
1
+ // There is special go module in `build` directory that is used to control tools versions.
2
+ // This file exists because go 1.18 doesn't allow go sub modules if root dirrectory is not a go module.
3
+
4
+ module api
5
+
6
+ go 1.18
@@ -28,8 +28,8 @@ option go_package = "go.temporal.io/api/batch/v1;batch";
28
28
  option java_package = "io.temporal.api.batch.v1";
29
29
  option java_multiple_files = true;
30
30
  option java_outer_classname = "MessageProto";
31
- option ruby_package = "Temporal::Api::Batch::V1";
32
- option csharp_namespace = "Temporal.Api.Batch.V1";
31
+ option ruby_package = "Temporalio::Api::Batch::V1";
32
+ option csharp_namespace = "Temporalio.Api.Batch.V1";
33
33
 
34
34
  import "dependencies/gogoproto/gogo.proto";
35
35
  import "google/protobuf/timestamp.proto";
@@ -79,4 +79,11 @@ message BatchOperationSignal {
79
79
  message BatchOperationCancellation {
80
80
  // The identity of the worker/client
81
81
  string identity = 1;
82
+ }
83
+
84
+ // BatchOperationDeletion sends deletion requests to batch workflows.
85
+ // Keep the parameter in sync with temporal.api.workflowservice.v1.DeleteWorkflowExecutionRequest.
86
+ message BatchOperationDeletion {
87
+ // The identity of the worker/client
88
+ string identity = 1;
82
89
  }