@hatchet-dev/typescript-sdk 1.12.0 → 1.13.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 (92) hide show
  1. package/clients/dispatcher/dispatcher-client.d.ts +14 -1
  2. package/clients/dispatcher/dispatcher-client.js +25 -2
  3. package/clients/hatchet-client/client-config.d.ts +59 -0
  4. package/clients/hatchet-client/client-config.js +7 -0
  5. package/clients/rest/generated/Api.d.ts +9 -1
  6. package/clients/rest/generated/data-contracts.d.ts +43 -7
  7. package/clients/rest/generated/data-contracts.js +13 -2
  8. package/clients/worker/worker.js +25 -1
  9. package/package.json +1 -1
  10. package/protoc/dispatcher/dispatcher.d.ts +46 -1
  11. package/protoc/dispatcher/dispatcher.js +214 -2
  12. package/protoc/v1/workflows.d.ts +11 -0
  13. package/protoc/v1/workflows.js +122 -2
  14. package/step.d.ts +24 -18
  15. package/step.js +9 -1
  16. package/v1/client/client.d.ts +30 -14
  17. package/v1/client/client.js +33 -5
  18. package/v1/client/worker/context.d.ts +6 -0
  19. package/v1/client/worker/context.js +8 -0
  20. package/v1/client/worker/deprecated/deprecation.d.ts +44 -0
  21. package/v1/client/worker/deprecated/deprecation.js +95 -0
  22. package/v1/client/worker/deprecated/index.d.ts +4 -0
  23. package/v1/client/worker/deprecated/index.js +15 -0
  24. package/v1/client/worker/deprecated/legacy-registration.d.ts +18 -0
  25. package/v1/client/worker/deprecated/legacy-registration.js +35 -0
  26. package/v1/client/worker/deprecated/legacy-v1-worker.d.ts +15 -0
  27. package/v1/client/worker/deprecated/legacy-v1-worker.js +39 -0
  28. package/v1/client/worker/deprecated/legacy-worker.d.ts +41 -0
  29. package/v1/client/worker/deprecated/legacy-worker.js +148 -0
  30. package/v1/client/worker/slot-utils.d.ts +21 -0
  31. package/v1/client/worker/slot-utils.js +73 -0
  32. package/v1/client/worker/worker-internal.d.ts +14 -3
  33. package/v1/client/worker/worker-internal.js +53 -13
  34. package/v1/client/worker/worker.d.ts +12 -15
  35. package/v1/client/worker/worker.js +45 -49
  36. package/v1/declaration.d.ts +63 -15
  37. package/v1/declaration.js +66 -2
  38. package/v1/examples/cancellations/workflow.d.ts +2 -2
  39. package/v1/examples/child_workflows/workflow.d.ts +4 -4
  40. package/v1/examples/concurrency-rr/workflow.d.ts +2 -2
  41. package/v1/examples/dag/interface-workflow.d.ts +1 -1
  42. package/v1/examples/dag/workflow.d.ts +1 -1
  43. package/v1/examples/dag_match_condition/complex-workflow.d.ts +1 -1
  44. package/v1/examples/dag_match_condition/workflow.d.ts +1 -1
  45. package/v1/examples/deep/workflow.d.ts +6 -6
  46. package/v1/examples/durable-event/workflow.d.ts +2 -2
  47. package/v1/examples/durable-sleep/workflow.d.ts +1 -1
  48. package/v1/examples/hatchet-client.d.ts +1 -1
  49. package/v1/examples/high-memory/workflow-with-child.d.ts +2 -2
  50. package/v1/examples/inferred-typing/workflow.d.ts +4 -4
  51. package/v1/examples/landing_page/event-signaling.d.ts +1 -1
  52. package/v1/examples/landing_page/flow-control.d.ts +1 -1
  53. package/v1/examples/landing_page/task-routing.d.ts +1 -1
  54. package/v1/examples/middleware/client.d.ts +26 -0
  55. package/v1/examples/middleware/client.js +39 -0
  56. package/v1/examples/middleware/recipes.d.ts +1 -0
  57. package/v1/examples/middleware/recipes.js +95 -0
  58. package/v1/examples/middleware/run.d.ts +1 -0
  59. package/v1/examples/middleware/run.js +29 -0
  60. package/v1/examples/middleware/worker.d.ts +1 -0
  61. package/v1/examples/middleware/worker.js +24 -0
  62. package/v1/examples/middleware/workflow.d.ts +15 -0
  63. package/v1/examples/middleware/workflow.js +18 -0
  64. package/v1/examples/migration-guides/hatchet-client.d.ts +1 -1
  65. package/v1/examples/migration-guides/mergent.d.ts +1 -1
  66. package/v1/examples/multiple_wf_concurrency/workflow.d.ts +1 -1
  67. package/v1/examples/non_retryable/workflow.d.ts +1 -1
  68. package/v1/examples/on_cron/workflow.d.ts +1 -1
  69. package/v1/examples/on_event/workflow.d.ts +3 -3
  70. package/v1/examples/on_failure/workflow.d.ts +1 -1
  71. package/v1/examples/on_success/workflow.d.ts +1 -1
  72. package/v1/examples/priority/workflow.d.ts +4 -4
  73. package/v1/examples/quickstart/hatchet-client.d.ts +1 -1
  74. package/v1/examples/quickstart/workflows/first-task.d.ts +1 -1
  75. package/v1/examples/retries/workflow.d.ts +3 -3
  76. package/v1/examples/simple/stub-workflow.d.ts +1 -1
  77. package/v1/examples/simple/workflow-with-child.d.ts +2 -2
  78. package/v1/examples/simple/workflow.d.ts +1 -1
  79. package/v1/examples/simple/zod.d.ts +1 -1
  80. package/v1/examples/sticky/workflow.d.ts +1 -1
  81. package/v1/examples/streaming/workflow.d.ts +1 -1
  82. package/v1/examples/timeouts/workflow.d.ts +1 -1
  83. package/v1/examples/with_timeouts/workflow.d.ts +2 -2
  84. package/v1/index.d.ts +1 -0
  85. package/v1/index.js +1 -0
  86. package/v1/slot-types.d.ts +5 -0
  87. package/v1/slot-types.js +9 -0
  88. package/v1/task.d.ts +2 -0
  89. package/v1/types.d.ts +10 -1
  90. package/version.d.ts +1 -1
  91. package/version.js +1 -1
  92. package/workflow.d.ts +58 -58
@@ -1,4 +1,4 @@
1
- import { ClientConfig, HatchetClientOptions, LegacyHatchetClient } from '../../clients/hatchet-client';
1
+ import { ClientConfig, HatchetClientOptions, LegacyHatchetClient, TaskMiddleware, InferMiddlewareBefore, InferMiddlewareAfter } from '../../clients/hatchet-client';
2
2
  import { AxiosRequestConfig } from 'axios';
3
3
  import WorkflowRunRef from '../../util/workflow-run-ref';
4
4
  import { Workflow as V0Workflow } from '../../workflow';
@@ -12,7 +12,7 @@ import { MetricsClient } from './features/metrics';
12
12
  import { WorkersClient } from './features/workers';
13
13
  import { WorkflowsClient } from './features/workflows';
14
14
  import { RunsClient } from './features/runs';
15
- import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } from '../types';
15
+ import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType, Resolved } from '../types';
16
16
  import { RatelimitsClient } from './features';
17
17
  import { AdminClient } from './admin';
18
18
  import { FiltersClient } from './features/filters';
@@ -21,11 +21,16 @@ import { CronClient } from './features/crons';
21
21
  import { CELClient } from './features/cel';
22
22
  import { TenantClient } from './features/tenant';
23
23
  import { WebhooksClient } from './features/webhooks';
24
+ type MergeIfNonEmpty<Base, Extra extends Record<string, any>> = keyof Extra extends never ? Base : Base & Extra;
24
25
  /**
25
26
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
26
27
  * It provides methods for creating and executing workflows, as well as managing workers.
28
+ *
29
+ * @template GlobalInput - Global input type required by all tasks. Set via `init<T>()`. Defaults to `{}`.
30
+ * @template MiddlewareBefore - Extra fields merged into task input by pre-middleware hooks. Inferred from middleware config.
31
+ * @template MiddlewareAfter - Extra fields merged into task output by post-middleware hooks. Inferred from middleware config.
27
32
  */
28
- export declare class HatchetClient implements IHatchetClient {
33
+ export declare class HatchetClient<GlobalInput extends Record<string, any> = {}, GlobalOutput extends Record<string, any> = {}, MiddlewareBefore extends Record<string, any> = {}, MiddlewareAfter extends Record<string, any> = {}> implements IHatchetClient {
29
34
  /** The underlying v0 client instance */
30
35
  _v0: LegacyHatchetClient;
31
36
  _api: Api;
@@ -47,12 +52,22 @@ export declare class HatchetClient implements IHatchetClient {
47
52
  constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig);
48
53
  /**
49
54
  * Static factory method to create a new Hatchet client instance.
50
- * @param config - Optional configuration for the client
51
- * @param options - Optional client options
52
- * @param axiosConfig - Optional Axios configuration for HTTP requests
53
- * @returns A new Hatchet client instance
54
- */
55
- static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
55
+ * @template T - Global input type required by all tasks created from this client. Defaults to `{}`.
56
+ * @template U - Global output type required by all tasks created from this client. Defaults to `{}`.
57
+ * @param config - Optional configuration for the client.
58
+ * @param options - Optional client options.
59
+ * @param axiosConfig - Optional Axios configuration for HTTP requests.
60
+ * @returns A new Hatchet client instance. Chain `.withMiddleware()` to attach typed middleware.
61
+ */
62
+ static init<T extends Record<string, any> = {}, U extends Record<string, any> = {}>(config?: Omit<Partial<ClientConfig>, 'middleware'>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient<T, U>;
63
+ /**
64
+ * Attaches middleware to this client and returns a re-typed instance
65
+ * with inferred pre/post middleware types.
66
+ *
67
+ * Use this after `init<T, U>()` to get full middleware return-type inference
68
+ * that TypeScript can't provide when global types are explicitly set on `init`.
69
+ */
70
+ withMiddleware<const M extends TaskMiddleware<Resolved<GlobalInput, MiddlewareBefore>, Resolved<GlobalOutput, MiddlewareAfter>>>(middleware: M): HatchetClient<GlobalInput, GlobalOutput, MiddlewareBefore & InferMiddlewareBefore<M>, MiddlewareAfter & InferMiddlewareAfter<M>>;
56
71
  private _config;
57
72
  get config(): ClientConfig;
58
73
  /**
@@ -63,7 +78,7 @@ export declare class HatchetClient implements IHatchetClient {
63
78
  * @returns A new Workflow instance
64
79
  * @note It is possible to create an orphaned workflow if no client is available using @hatchet/client CreateWorkflow
65
80
  */
66
- workflow<I extends InputType = UnknownInputType, O extends StrictWorkflowOutputType = {}>(options: CreateWorkflowOpts): WorkflowDeclaration<I, O>;
81
+ workflow<I extends InputType = UnknownInputType, O extends StrictWorkflowOutputType = {}>(options: CreateWorkflowOpts): WorkflowDeclaration<I, O, Resolved<GlobalInput, MiddlewareBefore>>;
67
82
  /**
68
83
  * Creates a new task workflow.
69
84
  * Types can be explicitly specified as generics or inferred from the function signature.
@@ -72,7 +87,7 @@ export declare class HatchetClient implements IHatchetClient {
72
87
  * @param options Task configuration options
73
88
  * @returns A TaskWorkflowDeclaration instance
74
89
  */
75
- task<I extends InputType = UnknownInputType, O extends OutputType = void>(options: CreateTaskWorkflowOpts<I, O>): TaskWorkflowDeclaration<I, O>;
90
+ task<I extends InputType = UnknownInputType, O extends OutputType = void>(options: CreateTaskWorkflowOpts<I & Resolved<GlobalInput, MiddlewareBefore>, MergeIfNonEmpty<O, GlobalOutput>>): TaskWorkflowDeclaration<I, O, GlobalInput, GlobalOutput, MiddlewareBefore, MiddlewareAfter>;
76
91
  /**
77
92
  * Creates a new task workflow with types inferred from the function parameter.
78
93
  * @template Fn The type of the task function with input and output extending JsonObject
@@ -81,7 +96,7 @@ export declare class HatchetClient implements IHatchetClient {
81
96
  */
82
97
  task<Fn extends (input: I, ctx?: any) => O | Promise<O>, I extends InputType = Parameters<Fn>[0] | UnknownInputType, O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
83
98
  fn: Fn;
84
- } & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
99
+ } & Omit<CreateTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O, GlobalInput, GlobalOutput, MiddlewareBefore, MiddlewareAfter>;
85
100
  /**
86
101
  * Creates a new durable task workflow.
87
102
  * Types can be explicitly specified as generics or inferred from the function signature.
@@ -90,7 +105,7 @@ export declare class HatchetClient implements IHatchetClient {
90
105
  * @param options Durable task configuration options
91
106
  * @returns A TaskWorkflowDeclaration instance for a durable task
92
107
  */
93
- durableTask<I extends InputType, O extends OutputType>(options: CreateDurableTaskWorkflowOpts<I, O>): TaskWorkflowDeclaration<I, O>;
108
+ durableTask<I extends InputType, O extends OutputType>(options: CreateDurableTaskWorkflowOpts<I & Resolved<GlobalInput, MiddlewareBefore>, MergeIfNonEmpty<O, GlobalOutput>>): TaskWorkflowDeclaration<I, O, GlobalInput, GlobalOutput, MiddlewareBefore, MiddlewareAfter>;
94
109
  /**
95
110
  * Creates a new durable task workflow with types inferred from the function parameter.
96
111
  * @template Fn The type of the durable task function with input and output extending JsonObject
@@ -99,7 +114,7 @@ export declare class HatchetClient implements IHatchetClient {
99
114
  */
100
115
  durableTask<Fn extends (input: I, ctx: V0DurableContext<I>) => O | Promise<O>, I extends InputType = Parameters<Fn>[0], O extends OutputType = ReturnType<Fn> extends Promise<infer P> ? P extends OutputType ? P : void : ReturnType<Fn> extends OutputType ? ReturnType<Fn> : void>(options: {
101
116
  fn: Fn;
102
- } & Omit<CreateDurableTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O>;
117
+ } & Omit<CreateDurableTaskWorkflowOpts<I, O>, 'fn'>): TaskWorkflowDeclaration<I, O, GlobalInput, GlobalOutput, MiddlewareBefore, MiddlewareAfter>;
103
118
  /**
104
119
  * Triggers a workflow run without waiting for completion.
105
120
  * @template I - The input type for the workflow
@@ -255,3 +270,4 @@ export declare class HatchetClient implements IHatchetClient {
255
270
  v0webhooks(workflows: V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
256
271
  runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
257
272
  }
273
+ export {};
@@ -41,6 +41,10 @@ const webhooks_1 = require("./features/webhooks");
41
41
  /**
42
42
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
43
43
  * It provides methods for creating and executing workflows, as well as managing workers.
44
+ *
45
+ * @template GlobalInput - Global input type required by all tasks. Set via `init<T>()`. Defaults to `{}`.
46
+ * @template MiddlewareBefore - Extra fields merged into task input by pre-middleware hooks. Inferred from middleware config.
47
+ * @template MiddlewareAfter - Extra fields merged into task output by post-middleware hooks. Inferred from middleware config.
44
48
  */
45
49
  class HatchetClient {
46
50
  /**
@@ -95,7 +99,7 @@ class HatchetClient {
95
99
  .warn('🚨⚠️‼️ YOU ARE USING A V0 ENGINE WITH A V1 SDK, WHICH IS NOT SUPPORTED. PLEASE UPGRADE YOUR ENGINE TO V1.🚨⚠️‼️');
96
100
  }
97
101
  })
98
- .catch((error) => {
102
+ .catch(() => {
99
103
  // Do nothing here
100
104
  });
101
105
  }
@@ -105,14 +109,38 @@ class HatchetClient {
105
109
  }
106
110
  /**
107
111
  * Static factory method to create a new Hatchet client instance.
108
- * @param config - Optional configuration for the client
109
- * @param options - Optional client options
110
- * @param axiosConfig - Optional Axios configuration for HTTP requests
111
- * @returns A new Hatchet client instance
112
+ * @template T - Global input type required by all tasks created from this client. Defaults to `{}`.
113
+ * @template U - Global output type required by all tasks created from this client. Defaults to `{}`.
114
+ * @param config - Optional configuration for the client.
115
+ * @param options - Optional client options.
116
+ * @param axiosConfig - Optional Axios configuration for HTTP requests.
117
+ * @returns A new Hatchet client instance. Chain `.withMiddleware()` to attach typed middleware.
112
118
  */
113
119
  static init(config, options, axiosConfig) {
114
120
  return new HatchetClient(config, options, axiosConfig);
115
121
  }
122
+ /**
123
+ * Attaches middleware to this client and returns a re-typed instance
124
+ * with inferred pre/post middleware types.
125
+ *
126
+ * Use this after `init<T, U>()` to get full middleware return-type inference
127
+ * that TypeScript can't provide when global types are explicitly set on `init`.
128
+ */
129
+ withMiddleware(middleware) {
130
+ const existing = this._config.middleware || {};
131
+ const toArray = (v) => {
132
+ if (v == null)
133
+ return [];
134
+ if (Array.isArray(v))
135
+ return [...v];
136
+ return [v];
137
+ };
138
+ this._config.middleware = {
139
+ before: [...toArray(existing.before), ...toArray(middleware.before)],
140
+ after: [...toArray(existing.after), ...toArray(middleware.after)],
141
+ };
142
+ return this;
143
+ }
116
144
  get config() {
117
145
  return this._config;
118
146
  }
@@ -113,6 +113,12 @@ export declare class Context<T, K = {}> {
113
113
  * @returns The task run ID.
114
114
  */
115
115
  taskRunExternalId(): string;
116
+ /**
117
+ * Gets the ID of the current task run.
118
+ * @returns The task run ID.
119
+ * @deprecated use taskRunExternalId() instead
120
+ */
121
+ taskRunId(): string;
116
122
  /**
117
123
  * Gets the number of times the current task has been retried.
118
124
  * @returns The retry count.
@@ -180,6 +180,14 @@ class Context {
180
180
  taskRunExternalId() {
181
181
  return this.action.taskRunExternalId;
182
182
  }
183
+ /**
184
+ * Gets the ID of the current task run.
185
+ * @returns The task run ID.
186
+ * @deprecated use taskRunExternalId() instead
187
+ */
188
+ taskRunId() {
189
+ return this.taskRunExternalId();
190
+ }
183
191
  /**
184
192
  * Gets the number of times the current task has been retried.
185
193
  * @returns The retry count.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Generic time-aware deprecation helper.
3
+ *
4
+ * Timeline (from a given start date, with configurable windows):
5
+ * 0 to warnDays: WARNING logged once per feature
6
+ * warnDays to errorDays: ERROR logged once per feature
7
+ * after errorDays: throws an error 1-in-5 calls (20% chance)
8
+ *
9
+ * Defaults: warnDays=90, errorDays=undefined (error phase disabled unless set).
10
+ */
11
+ import { Logger } from '../../../../util/logger';
12
+ export declare class DeprecationError extends Error {
13
+ feature: string;
14
+ constructor(feature: string, message: string);
15
+ }
16
+ export interface DeprecationOpts {
17
+ /** Days after start during which a warning is logged. Defaults to 90. */
18
+ warnDays?: number;
19
+ /** Days after start during which an error is logged.
20
+ * After this window, calls have a 20% chance of throwing.
21
+ * If undefined (default), the error/raise phase is never reached —
22
+ * the notice stays at error-level logging indefinitely. */
23
+ errorDays?: number;
24
+ }
25
+ /**
26
+ * Emit a time-aware deprecation notice.
27
+ *
28
+ * @param feature - A short identifier for deduplication (each feature logs once).
29
+ * @param message - The human-readable deprecation message.
30
+ * @param start - The Date when the deprecation window began.
31
+ * @param logger - A Logger instance for outputting warnings/errors.
32
+ * @param opts - Optional configuration for time windows.
33
+ * @throws DeprecationError after the errorDays window (~20% chance).
34
+ */
35
+ /**
36
+ * Parses a semver string like "v0.78.23" into [major, minor, patch].
37
+ * Returns [0, 0, 0] if parsing fails.
38
+ */
39
+ export declare function parseSemver(v: string): [number, number, number];
40
+ /**
41
+ * Returns true if semver string a is strictly less than b.
42
+ */
43
+ export declare function semverLessThan(a: string, b: string): boolean;
44
+ export declare function emitDeprecationNotice(feature: string, message: string, start: Date, logger: Logger, opts?: DeprecationOpts): void;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /**
3
+ * Generic time-aware deprecation helper.
4
+ *
5
+ * Timeline (from a given start date, with configurable windows):
6
+ * 0 to warnDays: WARNING logged once per feature
7
+ * warnDays to errorDays: ERROR logged once per feature
8
+ * after errorDays: throws an error 1-in-5 calls (20% chance)
9
+ *
10
+ * Defaults: warnDays=90, errorDays=undefined (error phase disabled unless set).
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.DeprecationError = void 0;
14
+ exports.parseSemver = parseSemver;
15
+ exports.semverLessThan = semverLessThan;
16
+ exports.emitDeprecationNotice = emitDeprecationNotice;
17
+ const DEFAULT_WARN_DAYS = 90;
18
+ const MS_PER_DAY = 24 * 60 * 60 * 1000;
19
+ /** Tracks which features have already been logged (keyed by feature name). */
20
+ const alreadyLogged = new Set();
21
+ class DeprecationError extends Error {
22
+ constructor(feature, message) {
23
+ super(`${feature}: ${message}`);
24
+ this.name = 'DeprecationError';
25
+ this.feature = feature;
26
+ }
27
+ }
28
+ exports.DeprecationError = DeprecationError;
29
+ /**
30
+ * Emit a time-aware deprecation notice.
31
+ *
32
+ * @param feature - A short identifier for deduplication (each feature logs once).
33
+ * @param message - The human-readable deprecation message.
34
+ * @param start - The Date when the deprecation window began.
35
+ * @param logger - A Logger instance for outputting warnings/errors.
36
+ * @param opts - Optional configuration for time windows.
37
+ * @throws DeprecationError after the errorDays window (~20% chance).
38
+ */
39
+ /**
40
+ * Parses a semver string like "v0.78.23" into [major, minor, patch].
41
+ * Returns [0, 0, 0] if parsing fails.
42
+ */
43
+ function parseSemver(v) {
44
+ let s = v.startsWith('v') ? v.slice(1) : v;
45
+ const dashIdx = s.indexOf('-');
46
+ if (dashIdx !== -1)
47
+ s = s.slice(0, dashIdx);
48
+ const parts = s.split('.');
49
+ if (parts.length !== 3)
50
+ return [0, 0, 0];
51
+ return [parseInt(parts[0], 10) || 0, parseInt(parts[1], 10) || 0, parseInt(parts[2], 10) || 0];
52
+ }
53
+ /**
54
+ * Returns true if semver string a is strictly less than b.
55
+ */
56
+ function semverLessThan(a, b) {
57
+ const [aMaj, aMin, aPat] = parseSemver(a);
58
+ const [bMaj, bMin, bPat] = parseSemver(b);
59
+ if (aMaj !== bMaj)
60
+ return aMaj < bMaj;
61
+ if (aMin !== bMin)
62
+ return aMin < bMin;
63
+ return aPat < bPat;
64
+ }
65
+ function emitDeprecationNotice(feature, message, start, logger, opts) {
66
+ var _a;
67
+ const warnMs = ((_a = opts === null || opts === void 0 ? void 0 : opts.warnDays) !== null && _a !== void 0 ? _a : DEFAULT_WARN_DAYS) * MS_PER_DAY;
68
+ const errorDays = opts === null || opts === void 0 ? void 0 : opts.errorDays;
69
+ const errorMs = errorDays != null ? errorDays * MS_PER_DAY : undefined;
70
+ const elapsed = Date.now() - start.getTime();
71
+ if (elapsed < warnMs) {
72
+ // Phase 1: warning
73
+ if (!alreadyLogged.has(feature)) {
74
+ logger.warn(message);
75
+ alreadyLogged.add(feature);
76
+ }
77
+ }
78
+ else if (errorMs === undefined || elapsed < errorMs) {
79
+ // Phase 2: error-level log (indefinite when errorDays is not set)
80
+ if (!alreadyLogged.has(feature)) {
81
+ logger.error(`${message} This fallback will be removed soon. Upgrade immediately.`);
82
+ alreadyLogged.add(feature);
83
+ }
84
+ }
85
+ else {
86
+ // Phase 3: throw 1-in-5 times
87
+ if (!alreadyLogged.has(feature)) {
88
+ logger.error(`${message} This fallback is no longer supported and will fail intermittently.`);
89
+ alreadyLogged.add(feature);
90
+ }
91
+ if (Math.random() < 0.2) {
92
+ throw new DeprecationError(feature, message);
93
+ }
94
+ }
95
+ }
@@ -0,0 +1,4 @@
1
+ export { isLegacyEngine, LegacyDualWorker } from './legacy-worker';
2
+ export { LegacyV1Worker } from './legacy-v1-worker';
3
+ export { legacyGetActionListener } from './legacy-registration';
4
+ export { emitDeprecationNotice, DeprecationError, parseSemver, semverLessThan, } from './deprecation';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.semverLessThan = exports.parseSemver = exports.DeprecationError = exports.emitDeprecationNotice = exports.legacyGetActionListener = exports.LegacyV1Worker = exports.LegacyDualWorker = exports.isLegacyEngine = void 0;
4
+ var legacy_worker_1 = require("./legacy-worker");
5
+ Object.defineProperty(exports, "isLegacyEngine", { enumerable: true, get: function () { return legacy_worker_1.isLegacyEngine; } });
6
+ Object.defineProperty(exports, "LegacyDualWorker", { enumerable: true, get: function () { return legacy_worker_1.LegacyDualWorker; } });
7
+ var legacy_v1_worker_1 = require("./legacy-v1-worker");
8
+ Object.defineProperty(exports, "LegacyV1Worker", { enumerable: true, get: function () { return legacy_v1_worker_1.LegacyV1Worker; } });
9
+ var legacy_registration_1 = require("./legacy-registration");
10
+ Object.defineProperty(exports, "legacyGetActionListener", { enumerable: true, get: function () { return legacy_registration_1.legacyGetActionListener; } });
11
+ var deprecation_1 = require("./deprecation");
12
+ Object.defineProperty(exports, "emitDeprecationNotice", { enumerable: true, get: function () { return deprecation_1.emitDeprecationNotice; } });
13
+ Object.defineProperty(exports, "DeprecationError", { enumerable: true, get: function () { return deprecation_1.DeprecationError; } });
14
+ Object.defineProperty(exports, "parseSemver", { enumerable: true, get: function () { return deprecation_1.parseSemver; } });
15
+ Object.defineProperty(exports, "semverLessThan", { enumerable: true, get: function () { return deprecation_1.semverLessThan; } });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Legacy worker registration using the deprecated `slots` proto field
3
+ * instead of `slotConfig`. For backward compatibility with engines
4
+ * that do not support multiple slot types.
5
+ */
6
+ import { DispatcherClient, WorkerLabels } from '../../../../clients/dispatcher/dispatcher-client';
7
+ import { ActionListener } from '../../../../clients/dispatcher/action-listener';
8
+ export interface LegacyRegistrationOptions {
9
+ workerName: string;
10
+ services: string[];
11
+ actions: string[];
12
+ slots: number;
13
+ labels: WorkerLabels;
14
+ }
15
+ /**
16
+ * Registers a worker using the legacy `slots` proto field instead of `slotConfig`.
17
+ */
18
+ export declare function legacyGetActionListener(dispatcher: DispatcherClient, options: LegacyRegistrationOptions): Promise<ActionListener>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * Legacy worker registration using the deprecated `slots` proto field
4
+ * instead of `slotConfig`. For backward compatibility with engines
5
+ * that do not support multiple slot types.
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.legacyGetActionListener = legacyGetActionListener;
18
+ const dispatcher_client_1 = require("../../../../clients/dispatcher/dispatcher-client");
19
+ const action_listener_1 = require("../../../../clients/dispatcher/action-listener");
20
+ /**
21
+ * Registers a worker using the legacy `slots` proto field instead of `slotConfig`.
22
+ */
23
+ function legacyGetActionListener(dispatcher, options) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const registration = yield dispatcher.client.register({
26
+ workerName: options.workerName,
27
+ services: options.services,
28
+ actions: options.actions,
29
+ slots: options.slots,
30
+ labels: options.labels ? (0, dispatcher_client_1.mapLabels)(options.labels) : undefined,
31
+ runtimeInfo: dispatcher.getRuntimeInfo(),
32
+ });
33
+ return new action_listener_1.ActionListener(dispatcher, registration.workerId);
34
+ });
35
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Legacy V1Worker subclass that registers with the old `slots` proto field
3
+ * instead of `slotConfig`. Used when connected to pre-slot-config engines.
4
+ */
5
+ import { ActionListener } from '../../../../clients/dispatcher/action-listener';
6
+ import { HatchetClient } from '../../..';
7
+ import { V1Worker } from '../worker-internal';
8
+ export declare class LegacyV1Worker extends V1Worker {
9
+ private _legacySlotCount;
10
+ constructor(client: HatchetClient, options: ConstructorParameters<typeof V1Worker>[1], legacySlots: number);
11
+ /**
12
+ * Override registration to use the legacy `slots` proto field.
13
+ */
14
+ protected createListener(): Promise<ActionListener>;
15
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Legacy V1Worker subclass that registers with the old `slots` proto field
4
+ * instead of `slotConfig`. Used when connected to pre-slot-config engines.
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.LegacyV1Worker = void 0;
17
+ const worker_internal_1 = require("../worker-internal");
18
+ const legacy_registration_1 = require("./legacy-registration");
19
+ class LegacyV1Worker extends worker_internal_1.V1Worker {
20
+ constructor(client, options, legacySlots) {
21
+ super(client, options);
22
+ this._legacySlotCount = legacySlots;
23
+ }
24
+ /**
25
+ * Override registration to use the legacy `slots` proto field.
26
+ */
27
+ createListener() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ return (0, legacy_registration_1.legacyGetActionListener)(this.client._v0.dispatcher, {
30
+ workerName: this.name,
31
+ services: ['default'],
32
+ actions: Object.keys(this.action_registry),
33
+ slots: this._legacySlotCount,
34
+ labels: this.labels,
35
+ });
36
+ });
37
+ }
38
+ }
39
+ exports.LegacyV1Worker = LegacyV1Worker;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Legacy dual-worker implementation for pre-slot-config engines.
3
+ *
4
+ * When connected to an older Hatchet engine that does not support multiple slot types,
5
+ * this module provides the old worker start flow which creates separate durable and
6
+ * non-durable workers, each registered with the legacy `slots` proto field.
7
+ */
8
+ import { HatchetClient } from '../../..';
9
+ import { CreateWorkerOpts } from '../worker';
10
+ import { LegacyV1Worker } from './legacy-v1-worker';
11
+ /**
12
+ * Checks if the connected engine is legacy by comparing its semantic version
13
+ * against the minimum required version for slot_config support.
14
+ * Returns true if the engine is legacy, false otherwise.
15
+ * Emits a time-aware deprecation notice when a legacy engine is detected.
16
+ */
17
+ export declare function isLegacyEngine(v1: HatchetClient): Promise<boolean>;
18
+ /**
19
+ * LegacyDualWorker manages two V1Worker instances (nonDurable + durable)
20
+ * for engines that don't support slot_config.
21
+ * Uses the legacy `slots` proto field (maxRuns) instead of `slotConfig`.
22
+ */
23
+ export declare class LegacyDualWorker {
24
+ private nonDurable;
25
+ private durable;
26
+ private name;
27
+ constructor(name: string, nonDurable: LegacyV1Worker, durable?: LegacyV1Worker);
28
+ /**
29
+ * Creates a legacy dual-worker setup from the given options.
30
+ * Workers are created with legacy registration (old `slots` proto field).
31
+ */
32
+ static create(v1: HatchetClient, name: string, options: CreateWorkerOpts): Promise<LegacyDualWorker>;
33
+ /**
34
+ * Starts both workers using Promise.all.
35
+ */
36
+ start(): Promise<void>;
37
+ /**
38
+ * Stops both workers.
39
+ */
40
+ stop(): Promise<void>;
41
+ }