@temporalio/core-bridge 1.0.1 → 1.3.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 (114) hide show
  1. package/Cargo.lock +786 -54
  2. package/Cargo.toml +2 -2
  3. package/common.js +7 -3
  4. package/index.d.ts +110 -3
  5. package/index.js +2 -6
  6. package/package.json +3 -3
  7. package/releases/aarch64-apple-darwin/index.node +0 -0
  8. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  9. package/releases/x86_64-apple-darwin/index.node +0 -0
  10. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  11. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  12. package/scripts/build.js +4 -3
  13. package/sdk-core/.buildkite/docker/Dockerfile +2 -1
  14. package/sdk-core/ARCHITECTURE.md +2 -2
  15. package/sdk-core/README.md +12 -0
  16. package/sdk-core/bridge-ffi/Cargo.toml +2 -2
  17. package/sdk-core/client/Cargo.toml +6 -4
  18. package/sdk-core/client/src/lib.rs +338 -215
  19. package/sdk-core/client/src/raw.rs +352 -106
  20. package/sdk-core/client/src/retry.rs +159 -133
  21. package/sdk-core/client/src/workflow_handle/mod.rs +1 -1
  22. package/sdk-core/core/Cargo.toml +18 -9
  23. package/sdk-core/core/src/core_tests/activity_tasks.rs +63 -23
  24. package/sdk-core/core/src/core_tests/child_workflows.rs +125 -3
  25. package/sdk-core/core/src/core_tests/local_activities.rs +6 -6
  26. package/sdk-core/core/src/core_tests/workers.rs +3 -2
  27. package/sdk-core/core/src/core_tests/workflow_tasks.rs +70 -2
  28. package/sdk-core/core/src/ephemeral_server/mod.rs +499 -0
  29. package/sdk-core/core/src/lib.rs +60 -26
  30. package/sdk-core/core/src/pollers/poll_buffer.rs +4 -4
  31. package/sdk-core/core/src/replay/mod.rs +3 -3
  32. package/sdk-core/core/src/retry_logic.rs +10 -9
  33. package/sdk-core/core/src/telemetry/mod.rs +10 -7
  34. package/sdk-core/core/src/test_help/mod.rs +18 -8
  35. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +10 -10
  36. package/sdk-core/core/src/worker/activities/local_activities.rs +13 -13
  37. package/sdk-core/core/src/worker/activities.rs +6 -12
  38. package/sdk-core/core/src/worker/client.rs +193 -64
  39. package/sdk-core/core/src/worker/mod.rs +14 -19
  40. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +3 -0
  41. package/sdk-core/core/src/worker/workflow/history_update.rs +5 -5
  42. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +133 -85
  43. package/sdk-core/core/src/worker/workflow/machines/mod.rs +3 -2
  44. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +160 -105
  45. package/sdk-core/core/src/worker/workflow/managed_run.rs +2 -1
  46. package/sdk-core/core/src/worker/workflow/mod.rs +59 -58
  47. package/sdk-core/core/src/worker/workflow/run_cache.rs +5 -3
  48. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +7 -5
  49. package/sdk-core/core-api/Cargo.toml +2 -2
  50. package/sdk-core/core-api/src/errors.rs +3 -11
  51. package/sdk-core/core-api/src/worker.rs +7 -0
  52. package/sdk-core/protos/api_upstream/.buildkite/Dockerfile +1 -1
  53. package/sdk-core/protos/api_upstream/.github/CODEOWNERS +1 -1
  54. package/sdk-core/protos/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +2 -6
  55. package/sdk-core/protos/api_upstream/.github/workflows/trigger-api-go-update.yml +29 -0
  56. package/sdk-core/protos/api_upstream/Makefile +2 -2
  57. package/sdk-core/protos/api_upstream/buf.yaml +1 -0
  58. package/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +86 -0
  59. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +26 -0
  60. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +46 -0
  61. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +7 -0
  62. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +14 -0
  63. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +51 -0
  64. package/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +18 -0
  65. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +57 -1
  66. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +1 -3
  67. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +4 -2
  68. package/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +11 -0
  69. package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +23 -0
  70. package/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +46 -0
  71. package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +1 -0
  72. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +172 -0
  73. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +30 -0
  74. package/sdk-core/protos/grpc/health/v1/health.proto +63 -0
  75. package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +18 -15
  76. package/sdk-core/protos/testsrv_upstream/Makefile +80 -0
  77. package/sdk-core/protos/testsrv_upstream/api-linter.yaml +38 -0
  78. package/sdk-core/protos/testsrv_upstream/buf.yaml +13 -0
  79. package/sdk-core/protos/testsrv_upstream/dependencies/gogoproto/gogo.proto +141 -0
  80. package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +63 -0
  81. package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +90 -0
  82. package/sdk-core/sdk/Cargo.toml +2 -2
  83. package/sdk-core/sdk/src/lib.rs +2 -2
  84. package/sdk-core/sdk/src/workflow_context/options.rs +36 -8
  85. package/sdk-core/sdk/src/workflow_context.rs +30 -6
  86. package/sdk-core/sdk/src/workflow_future.rs +4 -4
  87. package/sdk-core/sdk-core-protos/Cargo.toml +5 -5
  88. package/sdk-core/sdk-core-protos/build.rs +9 -1
  89. package/sdk-core/sdk-core-protos/src/history_builder.rs +6 -1
  90. package/sdk-core/sdk-core-protos/src/lib.rs +93 -32
  91. package/sdk-core/test-utils/Cargo.toml +3 -3
  92. package/sdk-core/test-utils/src/canned_histories.rs +58 -0
  93. package/sdk-core/test-utils/src/lib.rs +14 -10
  94. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +141 -0
  95. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +55 -5
  96. package/sdk-core/tests/integ_tests/polling_tests.rs +1 -1
  97. package/sdk-core/tests/integ_tests/queries_tests.rs +4 -4
  98. package/sdk-core/tests/integ_tests/visibility_tests.rs +93 -0
  99. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +93 -10
  100. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
  101. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +14 -14
  102. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +1 -1
  103. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +12 -12
  104. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +12 -1
  105. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +3 -3
  106. package/sdk-core/tests/integ_tests/workflow_tests.rs +19 -4
  107. package/sdk-core/tests/load_tests.rs +2 -1
  108. package/sdk-core/tests/main.rs +10 -0
  109. package/src/conversions.rs +138 -91
  110. package/src/helpers.rs +190 -0
  111. package/src/lib.rs +10 -912
  112. package/src/runtime.rs +436 -0
  113. package/src/testing.rs +67 -0
  114. package/src/worker.rs +465 -0
package/Cargo.toml CHANGED
@@ -22,8 +22,8 @@ log = "0.4"
22
22
  neon = { version = "0.10", default-features = false, features = ["napi-6", "event-queue-api"] }
23
23
  opentelemetry = "0.16"
24
24
  parking_lot = "0.12"
25
- prost = "0.9"
26
- prost-types = "0.9"
25
+ prost = "0.11"
26
+ prost-types = "0.11"
27
27
  tokio = "1.13"
28
28
  once_cell = "1.7.2"
29
29
  temporal-sdk-core = { version = "*", path = "./sdk-core/core" }
package/common.js CHANGED
@@ -29,7 +29,7 @@ class PrebuildError extends Error {
29
29
  }
30
30
  }
31
31
 
32
- function getPrebuiltPath() {
32
+ function getPrebuiltTargetName() {
33
33
  const arch = archAlias[os.arch()];
34
34
  if (arch === undefined) {
35
35
  throw new PrebuildError(`No prebuilt module for arch ${os.arch()}`);
@@ -38,7 +38,11 @@ function getPrebuiltPath() {
38
38
  if (platform === undefined) {
39
39
  throw new PrebuildError(`No prebuilt module for platform ${os.platform()}`);
40
40
  }
41
- const binary = path.resolve(__dirname, 'releases', `${arch}-${platform}`, 'index.node');
41
+ return `${arch}-${platform}`;
42
+ }
43
+
44
+ function getPrebuiltPath() {
45
+ const binary = path.resolve(__dirname, 'releases', getPrebuiltTargetName(), 'index.node');
42
46
  if (fs.existsSync(binary)) {
43
47
  return binary;
44
48
  } else {
@@ -46,4 +50,4 @@ function getPrebuiltPath() {
46
50
  }
47
51
  }
48
52
 
49
- module.exports = { targets, archAlias, platformMapping, PrebuildError, getPrebuiltPath };
53
+ module.exports = { targets, archAlias, platformMapping, PrebuildError, getPrebuiltPath, getPrebuiltTargetName };
package/index.d.ts CHANGED
@@ -241,10 +241,109 @@ export interface LogEntry {
241
241
  level: LogLevel;
242
242
  }
243
243
 
244
- export interface Worker {}
245
- export interface Runtime {}
246
- export interface Client {}
244
+ /**
245
+ * Which version of the executable to run.
246
+ */
247
+ export type EphemeralServerExecutable =
248
+ | {
249
+ type: 'cached-download';
250
+ /**
251
+ * Download destination directory or the system's temp directory if none set.
252
+ */
253
+ downloadDir?: string;
254
+ /**
255
+ * Optional version, can be set to a specific server release or "default" or "latest".
256
+ *
257
+ * At the time of writing the the server is released as part of the Java SDK - (https://github.com/temporalio/sdk-java/releases).
258
+ *
259
+ * @default "default" - get the best version for the current SDK version.
260
+ */
261
+ version?: string;
262
+ }
263
+ | {
264
+ type: 'existing-path';
265
+ /** Path to executable */
266
+ path: string;
267
+ };
268
+
269
+ /**
270
+ * Configuration for the time-skipping test server.
271
+ */
272
+ export interface TimeSkippingServerConfig {
273
+ type: 'time-skipping';
274
+ executable?: EphemeralServerExecutable;
275
+ /**
276
+ * Optional port to listen on, defaults to find a random free port.
277
+ */
278
+ port?: number;
279
+ /**
280
+ * Extra args to pass to the executable command.
281
+ */
282
+ extraArgs?: string[];
283
+ }
284
+
285
+ /**
286
+ * Configuration for temporalite.
287
+ */
288
+ export interface TemporaliteConfig {
289
+ type: 'temporalite';
290
+ executable?: EphemeralServerExecutable;
291
+ /**
292
+ * Namespace to use - created at startup.
293
+ *
294
+ * @default "default"
295
+ */
296
+ namespace?: string;
297
+ /**
298
+ * IP to bind to.
299
+ *
300
+ * @default 127.0.0.1
301
+ */
302
+ ip?: string;
303
+ /**
304
+ * Sqlite DB filename if persisting or non-persistent if none.
305
+ */
306
+ db_filename?: string;
307
+ /**
308
+ * Whether to enable the UI.
309
+ */
310
+ ui?: boolean;
311
+ /**
312
+ * Log format and level
313
+ * @default { format: "pretty", level" "warn" }
314
+ */
315
+ log?: { format: string; level: string };
316
+ /**
317
+ * Optional port to listen on, defaults to find a random free port.
318
+ */
319
+ port?: number;
320
+ /**
321
+ * Extra args to pass to the executable command.
322
+ */
323
+ extraArgs?: string[];
324
+ }
247
325
 
326
+ /**
327
+ * Configuration for spawning an ephemeral Temporal server.
328
+ *
329
+ * Both the time-skipping test server and temporalite are supported.
330
+ */
331
+ export type EphemeralServerConfig = TimeSkippingServerConfig | TemporaliteConfig;
332
+
333
+ export interface Worker {
334
+ type: 'Worker';
335
+ }
336
+ export interface Runtime {
337
+ type: 'Runtime';
338
+ }
339
+ export interface Client {
340
+ type: 'Client';
341
+ }
342
+ export interface EphemeralServer {
343
+ type: 'EphemeralServer';
344
+ }
345
+
346
+ export declare type Callback<T> = (err: Error, result: T) => void;
248
347
  export declare type PollCallback = (err: Error, result: ArrayBuffer) => void;
249
348
  export declare type WorkerCallback = (err: Error, result: Worker) => void;
250
349
  export declare type ClientCallback = (err: Error, result: Client) => void;
@@ -293,3 +392,11 @@ export declare function workerCompleteActivityTask(
293
392
  ): void;
294
393
  export declare function workerRecordActivityHeartbeat(worker: Worker, heartbeat: ArrayBuffer): void;
295
394
  export declare function getTimeOfDay(): [number, number];
395
+ export declare function startEphemeralServer(
396
+ runtime: Runtime,
397
+ config: EphemeralServerConfig,
398
+ sdkVersion: string,
399
+ callback: Callback<EphemeralServer>
400
+ ): void;
401
+ export declare function shutdownEphemeralServer(server: EphemeralServer, callback: Callback<EphemeralServer>): void;
402
+ export declare function getEphemeralServerTarget(server: EphemeralServer): string;
package/index.js CHANGED
@@ -1,12 +1,8 @@
1
- const { getPrebuiltPath, PrebuildError } = require('./common');
1
+ const { getPrebuiltPath } = require('./common');
2
2
 
3
3
  try {
4
4
  const prebuiltPath = getPrebuiltPath();
5
5
  module.exports = require(prebuiltPath);
6
6
  } catch (err) {
7
- if (err instanceof PrebuildError) {
8
- module.exports = require('./default-build/index.node');
9
- } else {
10
- throw err;
11
- }
7
+ throw err;
12
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/core-bridge",
3
- "version": "1.0.1",
3
+ "version": "1.3.0",
4
4
  "description": "Temporal.io SDK Core<>Node bridge",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
22
  "@opentelemetry/api": "^1.1.0",
23
- "@temporalio/internal-non-workflow-common": "^1.0.1",
23
+ "@temporalio/internal-non-workflow-common": "^1.3.0",
24
24
  "arg": "^5.0.2",
25
25
  "cargo-cp-artifact": "^0.1.6",
26
26
  "which": "^2.0.2"
@@ -43,5 +43,5 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "gitHead": "a1dae539e72b6b088b400998d7bef482e8ed52f1"
46
+ "gitHead": "966d51d3545a5e84102190f5b762160b9dfe99c2"
47
47
  }
package/scripts/build.js CHANGED
@@ -4,7 +4,7 @@ const fs = require('fs');
4
4
  const which = require('which');
5
5
  const { spawnSync } = require('child_process');
6
6
  const { version } = require('../package.json');
7
- const { targets, getPrebuiltPath, PrebuildError } = require('../common');
7
+ const { targets, getPrebuiltPath, getPrebuiltTargetName, PrebuildError } = require('../common');
8
8
 
9
9
  process.chdir(path.resolve(__dirname, '..'));
10
10
 
@@ -54,10 +54,11 @@ if (unsupportedTargets.length) {
54
54
  const forceBuild = args['--force'];
55
55
  const buildRelease = args['--release'] || process.env.BUILD_CORE_RELEASE !== undefined;
56
56
 
57
- function compile(target) {
57
+ function compile(requestedTarget) {
58
+ const target = requestedTarget ?? getPrebuiltTargetName();
58
59
  console.log('Compiling bridge', { target, buildRelease });
59
60
 
60
- const out = target ? `releases/${target}/index.node` : 'default-build/index.node';
61
+ const out = `releases/${target}/index.node`;
61
62
  try {
62
63
  fs.unlinkSync(out);
63
64
  } catch (err) {
@@ -1,8 +1,9 @@
1
- FROM rust:1.59
1
+ FROM rust:1.63
2
2
 
3
3
  RUN rustup component add rustfmt && \
4
4
  rustup component add clippy
5
5
 
6
6
  RUN cargo install cargo-tarpaulin
7
+ RUN apt-get update && apt-get install -y protobuf-compiler
7
8
 
8
9
  WORKDIR /sdk-core
@@ -66,11 +66,11 @@ async fn hello_activity(name: &str) -> String {
66
66
 
67
67
  We define the interface between the core and lang SDKs in terms of gRPC service definitions. The actual implementations of this "service" are not generated by gRPC generators, but the messages themselves are, and make it easier to hit the ground running in new languages.
68
68
 
69
- See the latest API definition [here](https://github.com/temporalio/sdk-core/blob/master/protos/local/core_interface.proto)
69
+ See the latest API definition [here](https://github.com/temporalio/sdk-core/tree/master/protos/local/temporal/sdk/core)
70
70
 
71
71
 
72
72
  ## Other topics
73
73
  - [Sticky task queues](arch_docs/sticky_queues.md)
74
74
 
75
75
  ## Workflow Processing Internals
76
- ![Workflow Internals](arch_docs/diagrams/workflow_internals.svg)
76
+ ![Workflow Internals](arch_docs/diagrams/workflow_internals.svg)
@@ -76,6 +76,18 @@ subtree. To update it, use:
76
76
 
77
77
  Do not question why this git command is the way it is. It is not our place to interpret git's ways.
78
78
 
79
+ The java testserver protos are also pulled from the sdk-java repo, but since we only need a
80
+ subdirectory of that repo, we just copy the files with read-tree:
81
+ ```bash
82
+ # add sdk-java as a remote if you have not already
83
+ git remote add -f -t master --no-tags testsrv-protos git@github.com:temporalio/sdk-java.git
84
+ # delete existing protos
85
+ git rm -rf protos/testsrv_upstream
86
+ # pull from upstream & commit
87
+ git read-tree --prefix protos/testsrv_upstream -u testsrv-protos/master:temporal-test-server/src/main/proto
88
+ git commit
89
+ ```
90
+
79
91
  ## Fetching Histories
80
92
  Tests which would like to replay stored histories rely on that history being made available in
81
93
  binary format. You can fetch histories in that format like so (from a local docker server):
@@ -14,11 +14,11 @@ crate-type = ["staticlib"]
14
14
  lazy_static = "1.4"
15
15
  libc = "0.2"
16
16
  log = "0.4"
17
- prost = "0.9"
17
+ prost = "0.11"
18
18
  temporal-sdk-core = { version = "0.1", path = "../core" }
19
19
  temporal-sdk-core-api = { version = "0.1", path = "../core-api" }
20
20
  temporal-sdk-core-protos = { version = "0.1", path = "../sdk-core-protos" }
21
21
  tokio = "1"
22
22
 
23
23
  [build-dependencies]
24
- cbindgen = "0.20.0"
24
+ cbindgen = "0.24"
@@ -19,20 +19,22 @@ derive_more = "0.99"
19
19
  futures = "0.3"
20
20
  futures-retry = "0.6.0"
21
21
  http = "0.2"
22
+ once_cell = "1.13"
22
23
  opentelemetry = { version = "0.17", features = ["metrics"] }
23
24
  parking_lot = "0.12"
24
- prost-types = "0.9"
25
+ prost-types = "0.11"
25
26
  thiserror = "1.0"
26
27
  tokio = "1.1"
27
- tonic = { version = "0.6", features = ["tls", "tls-roots"] }
28
+ tonic = { version = "0.8", features = ["tls", "tls-roots"] }
28
29
  tower = "0.4"
29
30
  tracing = "0.1"
30
31
  url = "2.2"
31
- uuid = { version = "0.8.2", features = ["v4"] }
32
+ uuid = { version = "1.1", features = ["v4"] }
32
33
 
33
34
  [dependencies.temporal-sdk-core-protos]
34
35
  path = "../sdk-core-protos"
35
36
  version = "0.1"
36
37
 
37
38
  [dev-dependencies]
38
- mockall = "0.11"
39
+ assert_matches = "1"
40
+ mockall = "0.11"