@temporalio/core-bridge 1.11.8 → 1.12.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 (205) hide show
  1. package/Cargo.lock +219 -193
  2. package/Cargo.toml +27 -8
  3. package/README.md +5 -0
  4. package/index.js +72 -12
  5. package/lib/errors.d.ts +25 -0
  6. package/lib/errors.js +76 -1
  7. package/lib/errors.js.map +1 -1
  8. package/lib/index.d.ts +11 -478
  9. package/lib/index.js +28 -5
  10. package/lib/index.js.map +1 -1
  11. package/lib/native.d.ts +330 -0
  12. package/lib/{worker-tuner.js → native.js} +1 -1
  13. package/lib/native.js.map +1 -0
  14. package/package.json +7 -3
  15. package/releases/aarch64-apple-darwin/index.node +0 -0
  16. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  17. package/releases/x86_64-apple-darwin/index.node +0 -0
  18. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  19. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  20. package/sdk-core/.cargo/config.toml +8 -2
  21. package/sdk-core/.cargo/multi-worker-manual-test +15 -0
  22. package/sdk-core/.github/workflows/per-pr.yml +40 -11
  23. package/sdk-core/AGENTS.md +73 -0
  24. package/sdk-core/ARCHITECTURE.md +71 -23
  25. package/sdk-core/Cargo.toml +1 -1
  26. package/sdk-core/README.md +4 -4
  27. package/sdk-core/arch_docs/workflow_task_chunking.md +51 -0
  28. package/sdk-core/client/Cargo.toml +1 -1
  29. package/sdk-core/client/src/lib.rs +49 -13
  30. package/sdk-core/client/src/metrics.rs +15 -16
  31. package/sdk-core/client/src/proxy.rs +2 -2
  32. package/sdk-core/client/src/raw.rs +54 -8
  33. package/sdk-core/client/src/retry.rs +109 -13
  34. package/sdk-core/client/src/worker_registry/mod.rs +4 -4
  35. package/sdk-core/client/src/workflow_handle/mod.rs +1 -1
  36. package/sdk-core/core/Cargo.toml +28 -8
  37. package/sdk-core/core/src/abstractions.rs +62 -10
  38. package/sdk-core/core/src/core_tests/activity_tasks.rs +180 -8
  39. package/sdk-core/core/src/core_tests/mod.rs +4 -4
  40. package/sdk-core/core/src/core_tests/queries.rs +18 -4
  41. package/sdk-core/core/src/core_tests/workers.rs +3 -3
  42. package/sdk-core/core/src/core_tests/workflow_tasks.rs +191 -25
  43. package/sdk-core/core/src/ephemeral_server/mod.rs +10 -3
  44. package/sdk-core/core/src/internal_flags.rs +14 -14
  45. package/sdk-core/core/src/lib.rs +5 -2
  46. package/sdk-core/core/src/pollers/mod.rs +1 -1
  47. package/sdk-core/core/src/pollers/poll_buffer.rs +495 -164
  48. package/sdk-core/core/src/protosext/mod.rs +3 -3
  49. package/sdk-core/core/src/replay/mod.rs +3 -3
  50. package/sdk-core/core/src/telemetry/metrics.rs +13 -4
  51. package/sdk-core/core/src/telemetry/mod.rs +72 -70
  52. package/sdk-core/core/src/telemetry/otel.rs +51 -54
  53. package/sdk-core/core/src/test_help/mod.rs +9 -3
  54. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +31 -11
  55. package/sdk-core/core/src/worker/activities/local_activities.rs +35 -28
  56. package/sdk-core/core/src/worker/activities.rs +58 -30
  57. package/sdk-core/core/src/worker/client/mocks.rs +3 -3
  58. package/sdk-core/core/src/worker/client.rs +155 -53
  59. package/sdk-core/core/src/worker/mod.rs +103 -95
  60. package/sdk-core/core/src/worker/nexus.rs +100 -73
  61. package/sdk-core/core/src/worker/tuner/resource_based.rs +14 -6
  62. package/sdk-core/core/src/worker/tuner.rs +4 -13
  63. package/sdk-core/core/src/worker/workflow/history_update.rs +47 -51
  64. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -4
  65. package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +127 -32
  66. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +1 -2
  67. package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +1 -1
  68. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +55 -42
  69. package/sdk-core/core/src/worker/workflow/managed_run.rs +45 -35
  70. package/sdk-core/core/src/worker/workflow/mod.rs +200 -97
  71. package/sdk-core/core/src/worker/workflow/wft_poller.rs +175 -4
  72. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +38 -36
  73. package/sdk-core/core-api/Cargo.toml +8 -0
  74. package/sdk-core/core-api/src/envconfig.rs +1544 -0
  75. package/sdk-core/core-api/src/lib.rs +2 -0
  76. package/sdk-core/core-api/src/telemetry/metrics.rs +8 -0
  77. package/sdk-core/core-api/src/telemetry.rs +36 -3
  78. package/sdk-core/core-api/src/worker.rs +301 -75
  79. package/sdk-core/docker/docker-compose-telem.yaml +1 -0
  80. package/sdk-core/etc/prometheus.yaml +6 -2
  81. package/sdk-core/histories/long_local_activity_with_update-0_history.bin +0 -0
  82. package/sdk-core/histories/long_local_activity_with_update-1_history.bin +0 -0
  83. package/sdk-core/histories/long_local_activity_with_update-2_history.bin +0 -0
  84. package/sdk-core/histories/long_local_activity_with_update-3_history.bin +0 -0
  85. package/sdk-core/sdk/src/activity_context.rs +5 -0
  86. package/sdk-core/sdk/src/interceptors.rs +73 -3
  87. package/sdk-core/sdk/src/lib.rs +15 -16
  88. package/sdk-core/sdk/src/workflow_context/options.rs +10 -0
  89. package/sdk-core/sdk/src/workflow_context.rs +48 -29
  90. package/sdk-core/sdk/src/workflow_future.rs +5 -6
  91. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/.github/workflows/push-to-buf.yml +20 -0
  92. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/CODEOWNERS +6 -0
  93. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/README.md +17 -6
  94. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/VERSION +1 -1
  95. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/buf.lock +7 -2
  96. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/buf.yaml +2 -0
  97. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/request_response.proto +78 -0
  98. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/service.proto +29 -0
  99. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/identity/v1/message.proto +74 -32
  100. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/namespace/v1/message.proto +45 -15
  101. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/nexus/v1/message.proto +7 -1
  102. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/operation/v1/message.proto +3 -3
  103. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/region/v1/message.proto +3 -3
  104. package/sdk-core/sdk-core-protos/protos/api_upstream/LICENSE +1 -1
  105. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +2 -0
  106. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +1103 -88
  107. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +1233 -151
  108. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/activity/v1/message.proto +0 -22
  109. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +19 -24
  110. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +0 -22
  111. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +12 -22
  112. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +45 -45
  113. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +0 -22
  114. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/command_type.proto +0 -22
  115. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +15 -22
  116. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +0 -22
  117. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/event_type.proto +4 -22
  118. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +0 -22
  119. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/namespace.proto +0 -22
  120. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/nexus.proto +0 -20
  121. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/query.proto +0 -22
  122. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +0 -22
  123. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/schedule.proto +0 -22
  124. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +0 -22
  125. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/update.proto +0 -22
  126. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/workflow.proto +4 -22
  127. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/errordetails/v1/message.proto +0 -22
  128. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/export/v1/message.proto +0 -22
  129. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -22
  130. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/filter/v1/message.proto +0 -22
  131. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +75 -49
  132. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/namespace/v1/message.proto +0 -22
  133. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +0 -20
  134. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +0 -22
  135. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +0 -22
  136. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/protocol/v1/message.proto +0 -22
  137. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/query/v1/message.proto +0 -22
  138. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/replication/v1/message.proto +0 -22
  139. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/rules/v1/message.proto +90 -0
  140. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +0 -22
  141. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/enhanced_stack_trace.proto +0 -22
  142. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +0 -22
  143. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/user_metadata.proto +0 -22
  144. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/workflow_metadata.proto +0 -22
  145. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +17 -38
  146. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/update/v1/message.proto +0 -22
  147. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/version/v1/message.proto +0 -22
  148. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +151 -44
  149. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +172 -65
  150. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +69 -28
  151. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/activity_task/activity_task.proto +18 -0
  152. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/common/common.proto +5 -0
  153. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/nexus/nexus.proto +16 -1
  154. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +21 -15
  155. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +3 -0
  156. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +3 -0
  157. package/sdk-core/sdk-core-protos/src/lib.rs +60 -16
  158. package/sdk-core/test-utils/src/lib.rs +157 -39
  159. package/sdk-core/tests/cloud_tests.rs +86 -0
  160. package/sdk-core/tests/fuzzy_workflow.rs +23 -26
  161. package/sdk-core/tests/global_metric_tests.rs +116 -0
  162. package/sdk-core/tests/heavy_tests.rs +127 -7
  163. package/sdk-core/tests/integ_tests/client_tests.rs +2 -8
  164. package/sdk-core/tests/integ_tests/metrics_tests.rs +100 -106
  165. package/sdk-core/tests/integ_tests/polling_tests.rs +94 -8
  166. package/sdk-core/tests/integ_tests/update_tests.rs +75 -6
  167. package/sdk-core/tests/integ_tests/worker_tests.rs +54 -5
  168. package/sdk-core/tests/integ_tests/worker_versioning_tests.rs +240 -0
  169. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +41 -3
  170. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +168 -8
  171. package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +285 -15
  172. package/sdk-core/tests/integ_tests/workflow_tests/priority.rs +12 -4
  173. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +3 -2
  174. package/sdk-core/tests/integ_tests/workflow_tests.rs +124 -74
  175. package/sdk-core/tests/main.rs +3 -51
  176. package/sdk-core/tests/manual_tests.rs +430 -0
  177. package/sdk-core/tests/runner.rs +28 -2
  178. package/src/client.rs +565 -0
  179. package/src/helpers/abort_controller.rs +204 -0
  180. package/src/helpers/callbacks.rs +299 -0
  181. package/src/helpers/errors.rs +302 -0
  182. package/src/helpers/future.rs +44 -0
  183. package/src/helpers/handles.rs +191 -0
  184. package/src/helpers/inspect.rs +18 -0
  185. package/src/helpers/json_string.rs +58 -0
  186. package/src/helpers/mod.rs +20 -0
  187. package/src/helpers/properties.rs +71 -0
  188. package/src/helpers/try_from_js.rs +213 -0
  189. package/src/helpers/try_into_js.rs +129 -0
  190. package/src/lib.rs +28 -40
  191. package/src/logs.rs +111 -0
  192. package/src/metrics.rs +325 -0
  193. package/src/runtime.rs +409 -498
  194. package/src/testing.rs +315 -57
  195. package/src/worker.rs +907 -378
  196. package/ts/errors.ts +57 -0
  197. package/ts/index.ts +10 -596
  198. package/ts/native.ts +496 -0
  199. package/lib/worker-tuner.d.ts +0 -167
  200. package/lib/worker-tuner.js.map +0 -1
  201. package/src/conversions/slot_supplier_bridge.rs +0 -291
  202. package/src/conversions.rs +0 -618
  203. package/src/errors.rs +0 -38
  204. package/src/helpers.rs +0 -297
  205. package/ts/worker-tuner.ts +0 -193
package/ts/errors.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as grpc from '@grpc/grpc-js';
1
2
  import { IllegalStateError } from '@temporalio/common';
2
3
  import { isError, SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
3
4
 
@@ -27,6 +28,48 @@ export class UnexpectedError extends Error {
27
28
  }
28
29
  }
29
30
 
31
+ export interface NativeServiceError {
32
+ name: 'ServiceError';
33
+ message: string;
34
+ code: number;
35
+ details: string;
36
+ metadata: Record<string, Buffer | string>;
37
+ stack?: string;
38
+ }
39
+
40
+ /**
41
+ * A gRPC call failed. The error carries the gRPC status code, message, and other details.
42
+ */
43
+ @SymbolBasedInstanceOfError('ServiceError')
44
+ export class ServiceError extends Error implements grpc.ServiceError {
45
+ constructor(
46
+ message: string,
47
+ public readonly code: grpc.StatusObject['code'],
48
+ public readonly details: string,
49
+ public readonly metadata: grpc.Metadata
50
+ ) {
51
+ super(message);
52
+ }
53
+
54
+ static fromNative(err: NativeServiceError): ServiceError {
55
+ const metadata = new grpc.Metadata();
56
+ for (const [k, v] of Object.entries(err.metadata ?? {})) {
57
+ metadata.set(k, v);
58
+ }
59
+ return new ServiceError(err.message, err.code ?? 0, err.details ?? '', metadata);
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Something unexpected happened, considered fatal
65
+ */
66
+ @SymbolBasedInstanceOfError('NativePromiseDroppedError')
67
+ export class NativePromiseDroppedError extends UnexpectedError {
68
+ constructor(message: string) {
69
+ super(message);
70
+ }
71
+ }
72
+
30
73
  export { IllegalStateError };
31
74
 
32
75
  // Check if the error's class is exactly Error (not a descendant of it), in a realm-safe way
@@ -57,6 +100,20 @@ export function convertFromNamedError(e: unknown, keepStackTrace: boolean): unkn
57
100
  newerr = new UnexpectedError(e.message, e);
58
101
  newerr.stack = keepStackTrace ? e.stack : undefined;
59
102
  return newerr;
103
+
104
+ case 'ServiceError':
105
+ newerr = ServiceError.fromNative(e as NativeServiceError);
106
+ newerr.stack = keepStackTrace ? e.stack : undefined;
107
+ return newerr;
108
+ }
109
+
110
+ // Neon ensures that dropping an unsettled Promise results in a rejection, which is
111
+ // much better than just hanging the JS process. Sad though that it does so with an
112
+ // error message that would mean nothing to a user.
113
+ if (e.message === '`neon::types::Deferred` was dropped without being settled') {
114
+ newerr = new NativePromiseDroppedError('Native Promise was dropped without being settled');
115
+ newerr.stack = keepStackTrace ? e.stack : undefined;
116
+ return newerr;
60
117
  }
61
118
  }
62
119
  return e;
package/ts/index.ts CHANGED
@@ -1,604 +1,18 @@
1
- import { LogLevel, Duration } from '@temporalio/common';
2
- import type { TLSConfig, ProxyConfig, HttpConnectProxyConfig } from '@temporalio/common/lib/internal-non-workflow';
3
- import { WorkerTuner } from './worker-tuner';
1
+ import * as native from './native';
2
+ import * as errors from './errors';
4
3
 
5
4
  export {
6
- WorkerTuner,
7
- SlotSupplier,
8
- ResourceBasedSlotOptions,
9
- ResourceBasedTunerOptions,
10
- FixedSizeSlotSupplier,
11
- CustomSlotSupplier,
12
- SlotInfo,
13
- WorkflowSlotInfo,
14
- ActivitySlotInfo,
15
- LocalActivitySlotInfo,
16
- SlotMarkUsedContext,
17
- SlotPermit,
18
- SlotReserveContext,
19
- SlotReleaseContext,
20
- } from './worker-tuner';
21
-
22
- export type { TLSConfig, ProxyConfig, HttpConnectProxyConfig };
23
-
24
- /** @deprecated Import from @temporalio/common instead */
25
- export { LogLevel };
26
-
27
- type Shadow<Base, New> = Base extends object
28
- ? New extends object
29
- ? {
30
- [K in keyof Base | keyof New]: K extends keyof Base
31
- ? K extends keyof New
32
- ? Shadow<Base[K], New[K]>
33
- : Base[K]
34
- : K extends keyof New
35
- ? New[K]
36
- : never;
37
- }
38
- : New
39
- : New;
40
-
41
- export interface RetryOptions {
42
- /** Initial wait time before the first retry. */
43
- initialInterval: number;
44
- /**
45
- * Randomization jitter that is used as a multiplier for the current retry interval
46
- * and is added or subtracted from the interval length.
47
- */
48
- randomizationFactor: number;
49
- /** Rate at which retry time should be increased, until it reaches max_interval. */
50
- multiplier: number;
51
- /** Maximum amount of time to wait between retries. */
52
- maxInterval: number;
53
- /** Maximum total amount of time requests should be retried for, if None is set then no limit will be used. */
54
- maxElapsedTime?: number;
55
- /** Maximum number of retry attempts. */
56
- maxRetries: number;
57
- }
58
-
59
- export interface ClientOptions {
60
- /**
61
- * The URL of the Temporal server to connect to
62
- */
63
- url: string;
64
-
65
- /** Version string for the whole node SDK. Should never be set by user */
66
- sdkVersion: string;
67
-
68
- /**
69
- * TLS configuration options.
70
- *
71
- * Pass undefined to use a non-encrypted connection or an empty object to
72
- * connect with TLS without any customization.
73
- */
74
- tls?: TLSConfig;
75
-
76
- /**
77
- * Proxying configuration.
78
- *
79
- * @experimental
80
- */
81
- proxy?: ProxyConfig;
82
-
83
- /**
84
- * Optional retry options for server requests.
85
- */
86
- retry?: RetryOptions;
87
-
88
- /**
89
- * Optional mapping of gRPC metadata (HTTP headers) to send with each request to the server.
90
- *
91
- * Set statically at connection time, can be replaced later using {@link clientUpdateHeaders}.
92
- */
93
- metadata?: Record<string, string>;
94
-
95
- /**
96
- * API key for Temporal. This becomes the "Authorization" HTTP header with "Bearer " prepended.
97
- * This is only set if RPC metadata doesn't already have an "authorization" key.
98
- *
99
- * Set statically at connection time, can be replaced later using {@link clientUpdateApiKey}.
100
- */
101
- apiKey?: string;
102
- }
103
-
104
- /**
105
- * Log directly to console
106
- *
107
- * @experimental
108
- */
109
- export interface ConsoleLogger {
110
- console: {}; // eslint-disable-line @typescript-eslint/no-empty-object-type
111
- }
112
-
113
- /**
114
- * Forward logs to {@link Runtime} logger
115
- *
116
- * @experimental
117
- */
118
- export interface ForwardLogger {
119
- forward: {
120
- /**
121
- * What level, if any, logs should be forwarded from core at
122
- *
123
- * @deprecated Use {@link TelemetryOptions.logging.filter} instead
124
- */
125
- level?: LogLevel;
126
- };
127
- }
128
-
129
- /**
130
- * Logger types supported by Core
131
- *
132
- * @experimental
133
- */
134
- export type Logger = ConsoleLogger | ForwardLogger;
135
-
136
- /**
137
- * OpenTelemetry Collector options for exporting metrics or traces
138
- *
139
- * @experimental
140
- */
141
- export interface OtelCollectorExporter {
142
- otel: {
143
- /**
144
- * URL of a gRPC OpenTelemetry collector.
145
- *
146
- * Syntax should generally look like `http://server:4317` (the `grpc://` is also fine). Core's OTLP
147
- * metric exporter does not support the 'OTLP/HTTP' protocol (e.g. `http://server:4318/v1/metrics`).
148
- * For greater flexibility, you may setup an OTel collector running as a sidecar (e.g. to proxy
149
- * OTLP/gRPC requests to a remote OTLP/HTTP endpoint).
150
- *
151
- * @format Starts with "grpc://" or "http://" for an unsecured connection (typical),
152
- * or "grpcs://" or "https://" for a TLS connection.
153
- * @note The `OTEL_EXPORTER_OTLP_ENDPOINT` environment variable, if set, will override this property.
154
- */
155
- url: string;
156
- /**
157
- * Optional set of HTTP request headers to send to Collector (e.g. for authentication)
158
- */
159
- headers?: Record<string, string>;
160
- /**
161
- * Specify how frequently in metrics should be exported.
162
- *
163
- * @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
164
- * @defaults 1 second
165
- */
166
- metricsExportInterval?: Duration;
167
- /**
168
- * If set to true, the exporter will use seconds for durations instead of milliseconds.
169
- */
170
- useSecondsForDurations?: boolean;
171
- };
172
- }
173
-
174
- /** @experimental */
175
- export type CompiledOtelMetricsExporter = Shadow<
176
- OtelCollectorExporter,
177
- {
178
- otel: { metricsExportInterval: number };
179
- }
180
- >;
181
-
182
- /**
183
- * Prometheus metrics exporter options
184
- *
185
- * @experimental
186
- */
187
- export interface PrometheusMetricsExporter {
188
- prometheus: {
189
- /**
190
- * Address to bind the Prometheus HTTP metrics exporter server
191
- * (for example, `0.0.0.0:1234`).
192
- *
193
- * Metrics will be available for scraping under the standard `/metrics` route.
194
- */
195
- bindAddress: string;
196
- /**
197
- * If set to true, all counter names will include a "_total" suffix.
198
- */
199
- countersTotalSuffix?: boolean;
200
- /**
201
- * If set to true, all histograms will include the unit in their name as a suffix.
202
- * EX: "_milliseconds"
203
- */
204
- unitSuffix?: boolean;
205
- /**
206
- * If set to true, the exporter will use seconds for durations instead of milliseconds.
207
- */
208
- useSecondsForDurations?: boolean;
209
- };
210
- }
211
-
212
- /**
213
- * Metrics exporters supported by Core
214
- *
215
- * `temporality` is the type of aggregation temporality for metric export. Applies to both Prometheus and OpenTelemetry exporters.
216
- *
217
- * See the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/ce50e4634efcba8da445cc23523243cb893905cb/specification/metrics/datamodel.md#temporality) for more information.
218
- *
219
- * @experimental
220
- */
221
- export type MetricsExporter = {
222
- temporality?: 'cumulative' | 'delta';
223
- } & (PrometheusMetricsExporter | OtelCollectorExporter);
224
-
225
- /** @experimental */
226
- export interface TelemetryOptions {
227
- /**
228
- * A string in the env filter format specified here:
229
- * https://docs.rs/tracing-subscriber/0.2.20/tracing_subscriber/struct.EnvFilter.html
230
- *
231
- * Which determines what tracing data is collected in the Core SDK.
232
- *
233
- * @deprecated Use `logging.filter` instead
234
- */
235
- tracingFilter?: string;
236
-
237
5
  /**
238
- * If set true, do not prefix metrics with `temporal_`. Will be removed eventually as
239
- * the prefix is consistent with other SDKs.
240
- *
241
- * @default `false`
6
+ * @internal This module is not intended to be used directly. Any API provided
7
+ * by this package is internal and subject to change without notice.
8
+ * @hidden
242
9
  */
243
- noTemporalPrefixForMetrics?: boolean;
10
+ native,
244
11
 
245
12
  /**
246
- * Control where to send Rust Core logs
13
+ * @internal This module is not intended to be used directly. Any API provided
14
+ * by this package is internal and subject to change without notice.
15
+ * @hidden
247
16
  */
248
- logging?: {
249
- /**
250
- * A string in (env filter format)[https://docs.rs/tracing-subscriber/0.2.20/tracing_subscriber/struct.EnvFilter.html]
251
- * which determines the verboseness of logging output.
252
- *
253
- * You can use {@link Runtime.makeTelemetryFilterString()} to easily build a correctly formatted filter
254
- * string based on desired log level for Core SDK and other native packages.
255
- *
256
- * **BACKWARD COMPATIBILITY**
257
- *
258
- * If `logging.filter` is missing, the following legacy values (if present) will be used instead (in the given order):
259
- * - {@link ForwardLogger.forward.level} => `makeTelemetryFilterString({ core: level, other: level })`
260
- * - {@link TelemetryOptions.tracingFilter}
261
- * - Default value of `makeTelemetryFilterString({ core: 'INFO', other: 'INFO'})`
262
- *
263
- * @default `makeTelemetryFilterString({ core: 'INFO', other: 'INFO'})` (with some exceptions, as described in backward compatibility note above)
264
- */
265
- filter?: string;
266
- } & Partial<Logger>;
267
-
268
- /**
269
- * Control exporting {@link NativeConnection} and {@link Worker} metrics.
270
- *
271
- * Turned off by default
272
- */
273
- metrics?: MetricsExporter;
274
-
275
- /**
276
- * @deprecated Core SDK tracing is no longer supported. This option is ignored.
277
- */
278
- tracing?: unknown;
279
- }
280
-
281
- /** @experimental */
282
- export type CompiledTelemetryOptions = {
283
- noTemporalPrefixForMetrics?: boolean;
284
- logging: {
285
- filter: string;
286
- } & (
287
- | { console: {} /* eslint-disable-line @typescript-eslint/no-empty-object-type */ }
288
- | { forward: {} /* eslint-disable-line @typescript-eslint/no-empty-object-type */ }
289
- );
290
- metrics?: {
291
- temporality?: 'cumulative' | 'delta';
292
- } & (PrometheusMetricsExporter | CompiledOtelMetricsExporter);
17
+ errors,
293
18
  };
294
-
295
- export interface WorkerOptions {
296
- /**
297
- * A human-readable string that can identify your worker
298
- */
299
- identity: string;
300
- /**
301
- * A string that should be unique to the exact worker code/binary being executed
302
- */
303
- buildId: string;
304
- /**
305
- * If set true, this worker opts into the worker versioning feature. This ensures it only receives
306
- * workflow tasks for workflows which it claims to be compatible with.
307
- *
308
- * For more information, see https://docs.temporal.io/workers#worker-versioning
309
- */
310
- useVersioning: boolean;
311
-
312
- /**
313
- * The task queue the worker will pull from
314
- */
315
- taskQueue: string;
316
-
317
- /**
318
- * The tuner the worker will use
319
- */
320
- tuner: WorkerTuner;
321
-
322
- nonStickyToStickyPollRatio: number;
323
-
324
- /**
325
- * Maximum number of Workflow tasks to poll concurrently.
326
- */
327
- maxConcurrentWorkflowTaskPolls: number;
328
-
329
- /**
330
- * Maximum number of Activity tasks to poll concurrently.
331
- */
332
- maxConcurrentActivityTaskPolls: number;
333
-
334
- /**
335
- * If set to `false` this worker will only handle workflow tasks and local activities, it will not
336
- * poll for activity tasks.
337
- */
338
- enableNonLocalActivities: boolean;
339
-
340
- /**
341
- * How long a workflow task is allowed to sit on the sticky queue before it is timed out
342
- * and moved to the non-sticky queue where it may be picked up by any worker.
343
- */
344
- stickyQueueScheduleToStartTimeoutMs: number;
345
-
346
- /**
347
- * Maximum number of Workflow instances to cache before automatic eviction
348
- */
349
- maxCachedWorkflows: number;
350
- /**
351
- * Longest interval for throttling activity heartbeats
352
- * @default 60 seconds
353
- */
354
- maxHeartbeatThrottleIntervalMs: number;
355
-
356
- /**
357
- * Default interval for throttling activity heartbeats in case
358
- * `ActivityOptions.heartbeat_timeout` is unset.
359
- * When the timeout *is* set in the `ActivityOptions`, throttling is set to
360
- * `heartbeat_timeout * 0.8`.
361
- * @default 30 seconds
362
- */
363
- defaultHeartbeatThrottleIntervalMs: number;
364
-
365
- /**
366
- * Sets the maximum number of activities per second the task queue will dispatch, controlled
367
- * server-side. Note that this only takes effect upon an activity poll request. If multiple
368
- * workers on the same queue have different values set, they will thrash with the last poller
369
- * winning.
370
- */
371
- maxTaskQueueActivitiesPerSecond?: number;
372
-
373
- /**
374
- * Limits the number of activities per second that this worker will process. The worker will
375
- * not poll for new activities if by doing so it might receive and execute an activity which
376
- * would cause it to exceed this limit. Must be a positive floating point number.
377
- */
378
- maxActivitiesPerSecond?: number;
379
- }
380
-
381
- export type LogEntryMetadata = {
382
- [key: string]: string | number | boolean | LogEntryMetadata;
383
- };
384
-
385
- export interface LogEntry {
386
- /** Log message */
387
- message: string;
388
- /**
389
- * Time since epoch [seconds, nanos].
390
- *
391
- * Should be switched to bigint once it is supported in neon.
392
- */
393
- timestamp: [number, number];
394
-
395
- /** Log level */
396
- level: LogLevel;
397
-
398
- /** Name of the Core subsystem that emitted that log entry */
399
- target: string;
400
-
401
- /*** Metadata fields */
402
- fields: LogEntryMetadata;
403
- }
404
-
405
- /**
406
- * Which version of the executable to run.
407
- */
408
- export type EphemeralServerExecutable =
409
- | {
410
- type: 'cached-download';
411
- /**
412
- * Download destination directory or the system's temp directory if none set.
413
- */
414
- downloadDir?: string;
415
- /**
416
- * Optional version, can be set to a specific server release or "default" or "latest".
417
- *
418
- * At the time of writing the the server is released as part of the Java SDK - (https://github.com/temporalio/sdk-java/releases).
419
- *
420
- * @default "default" - get the best version for the current SDK version.
421
- */
422
- version?: string;
423
- }
424
- | {
425
- type: 'existing-path';
426
- /** Path to executable */
427
- path: string;
428
- };
429
-
430
- /**
431
- * Configuration for the time-skipping test server.
432
- */
433
- export interface TimeSkippingServerConfig {
434
- type: 'time-skipping';
435
- executable?: EphemeralServerExecutable;
436
- /**
437
- * Optional port to listen on, defaults to find a random free port.
438
- */
439
- port?: number;
440
- /**
441
- * Extra args to pass to the executable command.
442
- *
443
- * Note that the Test Server implementation may be changed to another one in the future. Therefore, there is
444
- * no guarantee that server options, and particularly those provided through the `extraArgs` array, will continue to
445
- * be supported in the future.
446
- */
447
- extraArgs?: string[];
448
- }
449
-
450
- /**
451
- * Configuration for the Temporal CLI Dev Server.
452
- */
453
- export interface DevServerConfig {
454
- type: 'dev-server';
455
- executable?: EphemeralServerExecutable;
456
- /**
457
- * Namespace to use - created at startup.
458
- *
459
- * @default "default"
460
- */
461
- namespace?: string;
462
- /**
463
- * IP to bind to.
464
- *
465
- * @default 127.0.0.1
466
- */
467
- ip?: string;
468
- /**
469
- * Sqlite DB filename if persisting or non-persistent if none (default).
470
- */
471
- db_filename?: string;
472
- /**
473
- * Whether to enable the UI.
474
- *
475
- * @default false
476
- */
477
- ui?: boolean;
478
- /**
479
- * Log format and level
480
- * @default { format: "pretty", level" "warn" }
481
- */
482
- log?: { format: string; level: string };
483
- /**
484
- * Optional port to listen on, defaults to find a random free port.
485
- */
486
- port?: number;
487
- /**
488
- * Extra args to pass to the executable command.
489
- *
490
- * Note that the Dev Server implementation may be changed to another one in the future. Therefore, there is no
491
- * guarantee that Dev Server options, and particularly those provided through the `extraArgs` array, will continue to
492
- * be supported in the future.
493
- */
494
- extraArgs?: string[];
495
- }
496
-
497
- /**
498
- * Configuration for spawning an ephemeral Temporal server.
499
- *
500
- * Both the time-skipping Test Server and Temporal CLI dev server are supported.
501
- */
502
- export type EphemeralServerConfig = TimeSkippingServerConfig | DevServerConfig;
503
-
504
- export interface Worker {
505
- type: 'Worker';
506
- }
507
-
508
- export interface Runtime {
509
- type: 'Runtime';
510
- }
511
-
512
- export interface Client {
513
- type: 'Client';
514
- }
515
-
516
- export interface EphemeralServer {
517
- type: 'EphemeralServer';
518
- }
519
-
520
- export interface HistoryPusher {
521
- type: 'HistoryPusher';
522
- }
523
-
524
- export interface ReplayWorker {
525
- type: 'ReplayWorker';
526
- worker: Worker;
527
- pusher: HistoryPusher;
528
- }
529
-
530
- export declare type Callback<T> = (err: Error, result: T) => void;
531
- export declare type PollCallback = (err: Error, result: ArrayBuffer) => void;
532
- export declare type WorkerCallback = (err: Error, result: Worker) => void;
533
- export declare type ReplayWorkerCallback = (err: Error, worker: ReplayWorker) => void;
534
- export declare type ClientCallback = (err: Error, result: Client) => void;
535
- export declare type VoidCallback = (err: Error, result: void) => void;
536
- export declare type LogsCallback = (err: Error, result: LogEntry[]) => void;
537
-
538
- export declare function newRuntime(telemOptions: CompiledTelemetryOptions): Runtime;
539
-
540
- export declare function newClient(runtime: Runtime, clientOptions: ClientOptions, callback: ClientCallback): void;
541
-
542
- export declare function newWorker(client: Client, workerOptions: WorkerOptions, callback: WorkerCallback): void;
543
-
544
- export declare function newReplayWorker(
545
- runtime: Runtime,
546
- workerOptions: WorkerOptions,
547
- callback: ReplayWorkerCallback
548
- ): void;
549
-
550
- export declare function pushHistory(
551
- pusher: HistoryPusher,
552
- workflowId: string,
553
- history: ArrayBuffer,
554
- callback: VoidCallback
555
- ): void;
556
-
557
- export declare function closeHistoryStream(pusher: HistoryPusher): void;
558
-
559
- export declare function workerInitiateShutdown(worker: Worker, callback: VoidCallback): void;
560
-
561
- export declare function workerFinalizeShutdown(worker: Worker): void;
562
-
563
- export declare function clientUpdateHeaders(
564
- client: Client,
565
- headers: Record<string, string>,
566
- callback: VoidCallback
567
- ): void;
568
-
569
- export declare function clientUpdateApiKey(client: Client, apiKey: string, callback: VoidCallback): void;
570
-
571
- export declare function clientClose(client: Client): void;
572
-
573
- export declare function runtimeShutdown(runtime: Runtime, callback: VoidCallback): void;
574
-
575
- export declare function pollLogs(runtime: Runtime, callback: LogsCallback): void;
576
-
577
- export declare function workerPollWorkflowActivation(worker: Worker, callback: PollCallback): void;
578
-
579
- export declare function workerCompleteWorkflowActivation(
580
- worker: Worker,
581
- result: ArrayBuffer,
582
- callback: VoidCallback
583
- ): void;
584
-
585
- export declare function workerPollActivityTask(worker: Worker, callback: PollCallback): void;
586
-
587
- export declare function workerCompleteActivityTask(worker: Worker, result: ArrayBuffer, callback: VoidCallback): void;
588
-
589
- export declare function workerRecordActivityHeartbeat(worker: Worker, heartbeat: ArrayBuffer): void;
590
-
591
- export declare function getTimeOfDay(): [number, number];
592
-
593
- export declare function startEphemeralServer(
594
- runtime: Runtime,
595
- config: EphemeralServerConfig,
596
- sdkVersion: string,
597
- callback: Callback<EphemeralServer>
598
- ): void;
599
-
600
- export declare function shutdownEphemeralServer(server: EphemeralServer, callback: Callback<EphemeralServer>): void;
601
-
602
- export declare function getEphemeralServerTarget(server: EphemeralServer): string;
603
-
604
- export { ShutdownError, TransportError, UnexpectedError } from './errors';