@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,13 +1,20 @@
1
1
  import { Channel, ClientFactory } from 'nice-grpc';
2
- import { DispatcherClient as PbDispatcherClient, StepActionEvent, GroupKeyActionEvent, OverridesData, DeepPartial, RuntimeInfo } from '../../protoc/dispatcher';
2
+ import { DispatcherClient as PbDispatcherClient, StepActionEvent, GroupKeyActionEvent, OverridesData, DeepPartial, WorkerLabels as PbWorkerAffinityConfig, RuntimeInfo } from '../../protoc/dispatcher';
3
3
  import { ClientConfig } from '../hatchet-client/client-config';
4
4
  import { Logger } from '../../util/logger';
5
+ import { SlotConfig } from '../../v1/slot-types';
5
6
  import { ActionListener } from './action-listener';
6
7
  export type WorkerLabels = Record<string, string | number | undefined>;
7
8
  interface GetActionListenerOptions {
8
9
  workerName: string;
9
10
  services: string[];
10
11
  actions: string[];
12
+ slotConfig?: SlotConfig;
13
+ /** @deprecated use slotConfig */
14
+ slots?: number;
15
+ /** @deprecated use slotConfig */
16
+ durableSlots?: number;
17
+ /** @deprecated use slots */
11
18
  maxRuns?: number;
12
19
  labels: Record<string, string | number | undefined>;
13
20
  }
@@ -24,10 +31,16 @@ export declare class DispatcherClient {
24
31
  constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
25
32
  getRuntimeInfo(): RuntimeInfo;
26
33
  getActionListener(options: GetActionListenerOptions): Promise<ActionListener>;
34
+ /**
35
+ * Calls the GetVersion RPC. Returns the engine semantic version string.
36
+ * Throws a gRPC error with code UNIMPLEMENTED on older engines.
37
+ */
38
+ getVersion(): Promise<string>;
27
39
  sendStepActionEvent(in_: StepActionEventInput): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
28
40
  sendGroupKeyActionEvent(in_: GroupKeyActionEvent): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
29
41
  putOverridesData(in_: DeepPartial<OverridesData>): Promise<void | import("../../protoc/dispatcher").OverridesDataResponse>;
30
42
  refreshTimeout(incrementTimeoutBy: string, taskRunExternalId: string): Promise<import("../../protoc/dispatcher").RefreshTimeoutResponse>;
31
43
  upsertWorkerLabels(workerId: string, labels: WorkerLabels): Promise<import("../../protoc/dispatcher").UpsertWorkerLabelsResponse>;
32
44
  }
45
+ export declare function mapLabels(in_: WorkerLabels): Record<string, PbWorkerAffinityConfig>;
33
46
  export {};
@@ -24,10 +24,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.DispatcherClient = void 0;
27
+ exports.mapLabels = mapLabels;
27
28
  const dispatcher_1 = require("../../protoc/dispatcher");
28
29
  const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
29
30
  const retrier_1 = require("../../util/retrier");
30
31
  const version_1 = require("../../version");
32
+ const slot_types_1 = require("../../v1/slot-types");
31
33
  const action_listener_1 = require("./action-listener");
32
34
  class DispatcherClient {
33
35
  constructor(config, channel, factory) {
@@ -46,11 +48,32 @@ class DispatcherClient {
46
48
  getActionListener(options) {
47
49
  return __awaiter(this, void 0, void 0, function* () {
48
50
  // Register the worker
49
- const { maxRuns } = options, rest = __rest(options, ["maxRuns"]);
50
- const registration = yield this.client.register(Object.assign(Object.assign({}, rest), { slots: maxRuns, labels: options.labels ? mapLabels(options.labels) : undefined, runtimeInfo: this.getRuntimeInfo() }));
51
+ const slotConfig = options.slotConfig ||
52
+ (options.slots || options.durableSlots || options.maxRuns
53
+ ? Object.assign(Object.assign({}, (options.slots || options.maxRuns
54
+ ? { [slot_types_1.SlotType.Default]: options.slots || options.maxRuns || 0 }
55
+ : {})), (options.durableSlots ? { [slot_types_1.SlotType.Durable]: options.durableSlots } : {})) : undefined);
56
+ const registration = yield this.client.register({
57
+ workerName: options.workerName,
58
+ services: options.services,
59
+ actions: options.actions,
60
+ slotConfig,
61
+ labels: options.labels ? mapLabels(options.labels) : undefined,
62
+ runtimeInfo: this.getRuntimeInfo(),
63
+ });
51
64
  return new action_listener_1.ActionListener(this, registration.workerId);
52
65
  });
53
66
  }
67
+ /**
68
+ * Calls the GetVersion RPC. Returns the engine semantic version string.
69
+ * Throws a gRPC error with code UNIMPLEMENTED on older engines.
70
+ */
71
+ getVersion() {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const response = yield this.client.getVersion({});
74
+ return response.version;
75
+ });
76
+ }
54
77
  sendStepActionEvent(in_) {
55
78
  return __awaiter(this, void 0, void 0, function* () {
56
79
  const { taskId, taskRunExternalId } = in_, rest = __rest(in_, ["taskId", "taskRunExternalId"]);
@@ -1,5 +1,6 @@
1
1
  import { ChannelCredentials } from 'nice-grpc';
2
2
  import { z } from 'zod';
3
+ import type { Context } from '../../v1/client/worker/context';
3
4
  import { Logger, LogLevel } from '../../util/logger';
4
5
  declare const ClientTLSConfigSchema: z.ZodObject<{
5
6
  tls_strategy: z.ZodOptional<z.ZodEnum<["tls", "mtls", "none"]>>;
@@ -56,6 +57,16 @@ export declare const ClientConfigSchema: z.ZodObject<{
56
57
  log_level: z.ZodOptional<z.ZodEnum<["OFF", "DEBUG", "INFO", "WARN", "ERROR"]>>;
57
58
  tenant_id: z.ZodString;
58
59
  namespace: z.ZodOptional<z.ZodString>;
60
+ middleware: z.ZodOptional<z.ZodObject<{
61
+ before: z.ZodOptional<z.ZodAny>;
62
+ after: z.ZodOptional<z.ZodAny>;
63
+ }, "strip", z.ZodTypeAny, {
64
+ before?: any;
65
+ after?: any;
66
+ }, {
67
+ before?: any;
68
+ after?: any;
69
+ }>>;
59
70
  }, "strip", z.ZodTypeAny, {
60
71
  token: string;
61
72
  tls_config: {
@@ -74,6 +85,10 @@ export declare const ClientConfigSchema: z.ZodObject<{
74
85
  } | undefined;
75
86
  log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
76
87
  namespace?: string | undefined;
88
+ middleware?: {
89
+ before?: any;
90
+ after?: any;
91
+ } | undefined;
77
92
  }, {
78
93
  token: string;
79
94
  tls_config: {
@@ -92,12 +107,56 @@ export declare const ClientConfigSchema: z.ZodObject<{
92
107
  } | undefined;
93
108
  log_level?: "OFF" | "DEBUG" | "INFO" | "WARN" | "ERROR" | undefined;
94
109
  namespace?: string | undefined;
110
+ middleware?: {
111
+ before?: any;
112
+ after?: any;
113
+ } | undefined;
95
114
  }>;
96
115
  export type LogConstructor = (context: string, logLevel?: LogLevel) => Logger;
116
+ /**
117
+ * A middleware function that runs before every task invocation.
118
+ * Returns extra fields to replace the task input, or void to skip.
119
+ * @template T - The expected input type for the hook.
120
+ * @param input - The current task input.
121
+ * @param ctx - The task execution context.
122
+ * @returns The new input value, or void to pass through unchanged.
123
+ */
124
+ export type BeforeHookFn<T = any> = (input: T, ctx: Context<any>) => Record<string, any> | void | Promise<Record<string, any> | void>;
125
+ /**
126
+ * A middleware function that runs after every task invocation.
127
+ * Returns extra fields to replace the task output, or void to skip.
128
+ * @param output - The task output.
129
+ * @param ctx - The task execution context.
130
+ * @param input - The task input (after before-hooks have run).
131
+ * @returns The new output value, or void to pass through unchanged.
132
+ */
133
+ export type AfterHookFn<TOutput = any, TInput = any> = (output: TOutput, ctx: Context<any>, input: TInput) => Record<string, any> | void | Promise<Record<string, any> | void>;
134
+ /**
135
+ * Middleware hooks that run before/after every task invocation.
136
+ *
137
+ * Each hook can be a single function or an array of functions.
138
+ * When an array is provided the functions run in order and each
139
+ * result replaces the value (input for `before`, output for `after`).
140
+ *
141
+ * Return `void` (or `undefined`) from a hook to pass through unchanged.
142
+ */
143
+ export type TaskMiddleware<TInput = any, TOutput = any> = {
144
+ before?: BeforeHookFn<TInput> | readonly BeforeHookFn<TInput>[];
145
+ after?: AfterHookFn<TOutput, TInput> | readonly AfterHookFn<TOutput, TInput>[];
146
+ };
147
+ type NonVoidReturn<F> = F extends (...args: any[]) => infer R ? Exclude<Awaited<R>, void | undefined> : {};
148
+ type MergeReturns<T> = T extends readonly [infer F, ...infer Rest] ? NonVoidReturn<F> & MergeReturns<Rest> : {};
149
+ export type InferMiddlewareBefore<M> = M extends {
150
+ before: infer P;
151
+ } ? P extends (...args: any[]) => any ? NonVoidReturn<P> : P extends readonly any[] ? MergeReturns<P> : {} : {};
152
+ export type InferMiddlewareAfter<M> = M extends {
153
+ after: infer P;
154
+ } ? P extends (...args: any[]) => any ? NonVoidReturn<P> : P extends readonly any[] ? MergeReturns<P> : {} : {};
97
155
  export type ClientConfig = z.infer<typeof ClientConfigSchema> & {
98
156
  credentials?: ChannelCredentials;
99
157
  } & {
100
158
  logger: LogConstructor;
159
+ middleware?: TaskMiddleware;
101
160
  };
102
161
  export type ClientTLSConfig = z.infer<typeof ClientTLSConfigSchema>;
103
162
  export {};
@@ -13,6 +13,12 @@ const HealthcheckConfigSchema = zod_1.z.object({
13
13
  enabled: zod_1.z.boolean().optional().default(false),
14
14
  port: zod_1.z.number().optional().default(8001),
15
15
  });
16
+ const TaskMiddlewareSchema = zod_1.z
17
+ .object({
18
+ before: zod_1.z.any().optional(),
19
+ after: zod_1.z.any().optional(),
20
+ })
21
+ .optional();
16
22
  exports.ClientConfigSchema = zod_1.z.object({
17
23
  token: zod_1.z.string(),
18
24
  tls_config: ClientTLSConfigSchema,
@@ -22,4 +28,5 @@ exports.ClientConfigSchema = zod_1.z.object({
22
28
  log_level: zod_1.z.enum(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']).optional(),
23
29
  tenant_id: zod_1.z.string(),
24
30
  namespace: zod_1.z.string().optional(),
31
+ middleware: TaskMiddlewareSchema,
25
32
  });
@@ -1,4 +1,4 @@
1
- import { APIErrors, APIMeta, AcceptInviteRequest, BulkCreateEventRequest, CancelEventRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreateCronWorkflowTriggerRequest, CreateEventRequest, CreateSNSIntegrationRequest, CreateTenantAlertEmailGroupRequest, CreateTenantInviteRequest, CreateTenantRequest, CronWorkflows, CronWorkflowsList, CronWorkflowsOrderByField, Event, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, Events, ListAPIMetaIntegration, ListAPITokensResponse, ListSNSIntegrations, ListSlackWebhooks, LogLineLevelField, LogLineList, LogLineOrderByDirection, LogLineOrderByField, LogLineSearch, RateLimitList, RateLimitOrderByDirection, RateLimitOrderByField, RejectInviteRequest, ReplayEventRequest, ReplayWorkflowRunsRequest, ReplayWorkflowRunsResponse, RerunStepRunRequest, SNSIntegration, ScheduleWorkflowRunRequest, ScheduledRunStatus, ScheduledWorkflows, ScheduledWorkflowsBulkDeleteRequest, ScheduledWorkflowsBulkDeleteResponse, ScheduledWorkflowsBulkUpdateRequest, ScheduledWorkflowsBulkUpdateResponse, ScheduledWorkflowsList, ScheduledWorkflowsOrderByField, StepRun, StepRunArchiveList, StepRunEventList, TaskStats, Tenant, TenantAlertEmailGroup, TenantAlertEmailGroupList, TenantAlertingSettings, TenantInvite, TenantInviteList, TenantMember, TenantMemberList, TenantQueueMetrics, TenantResourcePolicy, TenantStepRunQueueMetrics, TriggerWorkflowRunRequest, UpdateCronWorkflowTriggerRequest, UpdateScheduledWorkflowRunRequest, UpdateTenantAlertEmailGroupRequest, UpdateTenantInviteRequest, UpdateTenantMemberRequest, UpdateTenantRequest, UpdateWorkerRequest, User, UserChangePasswordRequest, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, V1CELDebugRequest, V1CELDebugResponse, V1CancelTaskRequest, V1CancelledTasks, V1CreateFilterRequest, V1CreateWebhookRequest, V1DagChildren, V1Event, V1EventList, V1Filter, V1FilterList, V1LogLineList, V1ReplayTaskRequest, V1ReplayedTasks, V1TaskEventList, V1TaskPointMetrics, V1TaskRunMetrics, V1TaskStatus, V1TaskSummary, V1TaskSummaryList, V1TaskTimingList, V1TriggerWorkflowRunRequest, V1UpdateFilterRequest, V1UpdateWebhookRequest, V1Webhook, V1WebhookList, V1WebhookSourceName, V1WorkflowRunDetails, V1WorkflowRunDisplayNameList, V1WorkflowRunExternalIdList, WebhookWorkerCreateRequest, WebhookWorkerCreated, WebhookWorkerListResponse, WebhookWorkerRequestListResponse, Worker, WorkerList, Workflow, WorkflowID, WorkflowKindList, WorkflowList, WorkflowMetrics, WorkflowRun, WorkflowRunList, WorkflowRunOrderByDirection, WorkflowRunOrderByField, WorkflowRunShape, WorkflowRunStatus, WorkflowRunStatusList, WorkflowRunsCancelRequest, WorkflowRunsMetrics, WorkflowUpdateRequest, WorkflowVersion, WorkflowWorkersCount } from './data-contracts';
1
+ import { APIErrors, APIMeta, AcceptInviteRequest, BulkCreateEventRequest, CancelEventRequest, CreateAPITokenRequest, CreateAPITokenResponse, CreateCronWorkflowTriggerRequest, CreateEventRequest, CreateSNSIntegrationRequest, CreateTenantAlertEmailGroupRequest, CreateTenantInviteRequest, CreateTenantRequest, CronWorkflows, CronWorkflowsList, CronWorkflowsOrderByField, Event, EventData, EventKey, EventKeyList, EventList, EventOrderByDirection, EventOrderByField, EventSearch, Events, ListAPIMetaIntegration, ListAPITokensResponse, ListSNSIntegrations, ListSlackWebhooks, LogLineLevelField, LogLineList, LogLineOrderByDirection, LogLineOrderByField, LogLineSearch, RateLimitList, RateLimitOrderByDirection, RateLimitOrderByField, RejectInviteRequest, ReplayEventRequest, ReplayWorkflowRunsRequest, ReplayWorkflowRunsResponse, RerunStepRunRequest, SNSIntegration, ScheduleWorkflowRunRequest, ScheduledRunStatus, ScheduledWorkflows, ScheduledWorkflowsBulkDeleteRequest, ScheduledWorkflowsBulkDeleteResponse, ScheduledWorkflowsBulkUpdateRequest, ScheduledWorkflowsBulkUpdateResponse, ScheduledWorkflowsList, ScheduledWorkflowsOrderByField, StepRun, StepRunArchiveList, StepRunEventList, TaskStats, Tenant, TenantAlertEmailGroup, TenantAlertEmailGroupList, TenantAlertingSettings, TenantInvite, TenantInviteList, TenantMember, TenantMemberList, TenantQueueMetrics, TenantResourcePolicy, TenantStepRunQueueMetrics, TriggerWorkflowRunRequest, UpdateCronWorkflowTriggerRequest, UpdateScheduledWorkflowRunRequest, UpdateTenantAlertEmailGroupRequest, UpdateTenantInviteRequest, UpdateTenantMemberRequest, UpdateTenantRequest, UpdateWorkerRequest, User, UserChangePasswordRequest, UserLoginRequest, UserRegisterRequest, UserTenantMembershipsList, V1CELDebugRequest, V1CELDebugResponse, V1CancelTaskRequest, V1CancelledTasks, V1CreateFilterRequest, V1CreateWebhookRequest, V1DagChildren, V1Event, V1EventList, V1Filter, V1FilterList, V1LogLineLevel, V1LogLineList, V1LogLineOrderByDirection, V1ReplayTaskRequest, V1ReplayedTasks, V1TaskEventList, V1TaskPointMetrics, V1TaskRunMetrics, V1TaskStatus, V1TaskSummary, V1TaskSummaryList, V1TaskTimingList, V1TriggerWorkflowRunRequest, V1UpdateFilterRequest, V1UpdateWebhookRequest, V1Webhook, V1WebhookList, V1WebhookSourceName, V1WorkflowRunDetails, V1WorkflowRunDisplayNameList, V1WorkflowRunExternalIdList, WebhookWorkerCreateRequest, WebhookWorkerCreated, WebhookWorkerListResponse, WebhookWorkerRequestListResponse, Worker, WorkerList, Workflow, WorkflowID, WorkflowKindList, WorkflowList, WorkflowMetrics, WorkflowRun, WorkflowRunList, WorkflowRunOrderByDirection, WorkflowRunOrderByField, WorkflowRunShape, WorkflowRunStatus, WorkflowRunStatusList, WorkflowRunsCancelRequest, WorkflowRunsMetrics, WorkflowUpdateRequest, WorkflowVersion, WorkflowWorkersCount } from './data-contracts';
2
2
  import { HttpClient, RequestParams } from './http-client';
3
3
  export declare class Api<SecurityDataType = unknown> extends HttpClient<SecurityDataType> {
4
4
  /**
@@ -60,6 +60,14 @@ export declare class Api<SecurityDataType = unknown> extends HttpClient<Security
60
60
  * @format date-time
61
61
  */
62
62
  until?: string;
63
+ /** A full-text search query to filter for */
64
+ search?: string;
65
+ /** The log level(s) to include */
66
+ levels?: V1LogLineLevel[];
67
+ /** The direction to order by */
68
+ order_by_direction?: V1LogLineOrderByDirection;
69
+ /** The attempt number to filter for */
70
+ attempt?: number;
63
71
  }, params?: RequestParams) => Promise<import("axios").AxiosResponse<V1LogLineList, any, {}>>;
64
72
  /**
65
73
  * @description Cancel tasks
@@ -17,7 +17,8 @@ export declare enum WebhookWorkerRequestMethod {
17
17
  export declare enum WorkerRuntimeSDKs {
18
18
  GOLANG = "GOLANG",
19
19
  PYTHON = "PYTHON",
20
- TYPESCRIPT = "TYPESCRIPT"
20
+ TYPESCRIPT = "TYPESCRIPT",
21
+ RUBY = "RUBY"
21
22
  }
22
23
  export declare enum WorkerType {
23
24
  SELFHOSTED = "SELFHOSTED",
@@ -91,6 +92,10 @@ export declare enum StepRunStatus {
91
92
  CANCELLING = "CANCELLING",
92
93
  BACKOFF = "BACKOFF"
93
94
  }
95
+ export declare enum ConcurrencyScope {
96
+ WORKFLOW = "WORKFLOW",
97
+ TASK = "TASK"
98
+ }
94
99
  export declare enum ConcurrencyLimitStrategy {
95
100
  CANCEL_IN_PROGRESS = "CANCEL_IN_PROGRESS",
96
101
  DROP_NEWEST = "DROP_NEWEST",
@@ -160,7 +165,6 @@ export declare enum TenantResource {
160
165
  WORKER = "WORKER",
161
166
  WORKER_SLOT = "WORKER_SLOT",
162
167
  EVENT = "EVENT",
163
- WORKFLOW_RUN = "WORKFLOW_RUN",
164
168
  TASK_RUN = "TASK_RUN",
165
169
  CRON = "CRON",
166
170
  SCHEDULE = "SCHEDULE",
@@ -192,7 +196,8 @@ export declare enum V1WebhookSourceName {
192
196
  GITHUB = "GITHUB",
193
197
  STRIPE = "STRIPE",
194
198
  SLACK = "SLACK",
195
- LINEAR = "LINEAR"
199
+ LINEAR = "LINEAR",
200
+ SVIX = "SVIX"
196
201
  }
197
202
  export declare enum TenantEnvironment {
198
203
  Local = "local",
@@ -203,6 +208,10 @@ export declare enum TenantVersion {
203
208
  V0 = "V0",
204
209
  V1 = "V1"
205
210
  }
211
+ export declare enum V1LogLineOrderByDirection {
212
+ ASC = "ASC",
213
+ DESC = "DESC"
214
+ }
206
215
  export declare enum V1LogLineLevel {
207
216
  DEBUG = "DEBUG",
208
217
  INFO = "INFO",
@@ -1392,6 +1401,10 @@ export interface Step {
1392
1401
  action: string;
1393
1402
  /** The timeout of the step. */
1394
1403
  timeout?: string;
1404
+ /** Whether the step is durable. */
1405
+ isDurable?: boolean;
1406
+ /** Slot requests for the step (slot_type -> units). */
1407
+ slotRequests?: Record<string, number>;
1395
1408
  children?: string[];
1396
1409
  parents?: string[];
1397
1410
  }
@@ -1598,6 +1611,21 @@ export interface WorkflowTriggers {
1598
1611
  events?: WorkflowTriggerEventRef[];
1599
1612
  crons?: WorkflowTriggerCronRef[];
1600
1613
  }
1614
+ export interface ConcurrencySetting {
1615
+ /**
1616
+ * The maximum number of concurrent workflow runs.
1617
+ * @format int32
1618
+ */
1619
+ maxRuns: number;
1620
+ /** The strategy to use when the concurrency limit is reached. */
1621
+ limitStrategy: ConcurrencyLimitStrategy;
1622
+ /** The concurrency expression, used to generate a key from task inputs, metadata, etc. */
1623
+ expression: string;
1624
+ /** The readable id of the step to which this concurrency setting applies. */
1625
+ stepReadableId?: string;
1626
+ /** The scope of the concurrency setting. */
1627
+ scope: ConcurrencyScope;
1628
+ }
1601
1629
  export interface WorkflowVersion {
1602
1630
  metadata: APIResourceMeta;
1603
1631
  /** The version of the workflow. */
@@ -1618,6 +1646,9 @@ export interface WorkflowVersion {
1618
1646
  scheduleTimeout?: string;
1619
1647
  jobs?: Job[];
1620
1648
  workflowConfig?: object;
1649
+ v1Concurrency?: ConcurrencySetting[];
1650
+ /** The JSON schema for the workflow input. */
1651
+ inputJsonSchema?: object;
1621
1652
  }
1622
1653
  export interface TriggerWorkflowRunRequest {
1623
1654
  input: object;
@@ -1900,6 +1931,13 @@ export interface RecentStepRuns {
1900
1931
  /** @format uuid */
1901
1932
  workflowRunId: string;
1902
1933
  }
1934
+ /** Slot availability and limits for a slot type. */
1935
+ export interface WorkerSlotConfig {
1936
+ /** The number of available units for this slot type. */
1937
+ available?: number;
1938
+ /** The maximum number of units for this slot type. */
1939
+ limit: number;
1940
+ }
1903
1941
  export interface WorkerLabel {
1904
1942
  metadata: APIResourceMeta;
1905
1943
  /** The key of the label. */
@@ -1941,10 +1979,8 @@ export interface Worker {
1941
1979
  recentStepRuns?: RecentStepRuns[];
1942
1980
  /** The status of the worker. */
1943
1981
  status?: 'ACTIVE' | 'INACTIVE' | 'PAUSED';
1944
- /** The maximum number of runs this worker can execute concurrently. */
1945
- maxRuns?: number;
1946
- /** The number of runs this worker can execute concurrently. */
1947
- availableRuns?: number;
1982
+ /** Slot availability and limits for this worker (slot_type -> { available, limit }). */
1983
+ slotConfig?: Record<string, WorkerSlotConfig>;
1948
1984
  /**
1949
1985
  * the id of the assigned dispatcher, in UUID format
1950
1986
  * @format uuid
@@ -11,7 +11,7 @@
11
11
  * ---------------------------------------------------------------
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.V1TaskStatus = exports.V1WorkflowType = exports.V1TaskEventType = exports.V1LogLineLevel = exports.TenantVersion = exports.TenantEnvironment = exports.V1WebhookSourceName = exports.V1WebhookAuthType = exports.V1WebhookHMACAlgorithm = exports.V1WebhookHMACEncoding = exports.V1CELDebugResponseStatus = exports.TenantResource = exports.TenantMemberRole = exports.WorkflowRunStatus = exports.EventOrderByField = exports.EventOrderByDirection = exports.RateLimitOrderByField = exports.RateLimitOrderByDirection = exports.ScheduledWorkflowsMethod = exports.ScheduledWorkflowsOrderByField = exports.WorkflowRunOrderByDirection = exports.ScheduledRunStatus = exports.CronWorkflowsMethod = exports.CronWorkflowsOrderByField = exports.ConcurrencyLimitStrategy = exports.StepRunStatus = exports.JobRunStatus = exports.LogLineLevel = exports.LogLineOrderByField = exports.LogLineOrderByDirection = exports.StepRunEventReason = exports.StepRunEventSeverity = exports.WorkflowKind = exports.WorkflowRunOrderByField = exports.WorkerType = exports.WorkerRuntimeSDKs = exports.WebhookWorkerRequestMethod = exports.PullRequestState = exports.V1TaskRunStatus = void 0;
14
+ exports.V1TaskStatus = exports.V1WorkflowType = exports.V1TaskEventType = exports.V1LogLineLevel = exports.V1LogLineOrderByDirection = exports.TenantVersion = exports.TenantEnvironment = exports.V1WebhookSourceName = exports.V1WebhookAuthType = exports.V1WebhookHMACAlgorithm = exports.V1WebhookHMACEncoding = exports.V1CELDebugResponseStatus = exports.TenantResource = exports.TenantMemberRole = exports.WorkflowRunStatus = exports.EventOrderByField = exports.EventOrderByDirection = exports.RateLimitOrderByField = exports.RateLimitOrderByDirection = exports.ScheduledWorkflowsMethod = exports.ScheduledWorkflowsOrderByField = exports.WorkflowRunOrderByDirection = exports.ScheduledRunStatus = exports.CronWorkflowsMethod = exports.CronWorkflowsOrderByField = exports.ConcurrencyLimitStrategy = exports.ConcurrencyScope = exports.StepRunStatus = exports.JobRunStatus = exports.LogLineLevel = exports.LogLineOrderByField = exports.LogLineOrderByDirection = exports.StepRunEventReason = exports.StepRunEventSeverity = exports.WorkflowKind = exports.WorkflowRunOrderByField = exports.WorkerType = exports.WorkerRuntimeSDKs = exports.WebhookWorkerRequestMethod = exports.PullRequestState = exports.V1TaskRunStatus = void 0;
15
15
  var V1TaskRunStatus;
16
16
  (function (V1TaskRunStatus) {
17
17
  V1TaskRunStatus["PENDING"] = "PENDING";
@@ -36,6 +36,7 @@ var WorkerRuntimeSDKs;
36
36
  WorkerRuntimeSDKs["GOLANG"] = "GOLANG";
37
37
  WorkerRuntimeSDKs["PYTHON"] = "PYTHON";
38
38
  WorkerRuntimeSDKs["TYPESCRIPT"] = "TYPESCRIPT";
39
+ WorkerRuntimeSDKs["RUBY"] = "RUBY";
39
40
  })(WorkerRuntimeSDKs || (exports.WorkerRuntimeSDKs = WorkerRuntimeSDKs = {}));
40
41
  var WorkerType;
41
42
  (function (WorkerType) {
@@ -119,6 +120,11 @@ var StepRunStatus;
119
120
  StepRunStatus["CANCELLING"] = "CANCELLING";
120
121
  StepRunStatus["BACKOFF"] = "BACKOFF";
121
122
  })(StepRunStatus || (exports.StepRunStatus = StepRunStatus = {}));
123
+ var ConcurrencyScope;
124
+ (function (ConcurrencyScope) {
125
+ ConcurrencyScope["WORKFLOW"] = "WORKFLOW";
126
+ ConcurrencyScope["TASK"] = "TASK";
127
+ })(ConcurrencyScope || (exports.ConcurrencyScope = ConcurrencyScope = {}));
122
128
  var ConcurrencyLimitStrategy;
123
129
  (function (ConcurrencyLimitStrategy) {
124
130
  ConcurrencyLimitStrategy["CANCEL_IN_PROGRESS"] = "CANCEL_IN_PROGRESS";
@@ -202,7 +208,6 @@ var TenantResource;
202
208
  TenantResource["WORKER"] = "WORKER";
203
209
  TenantResource["WORKER_SLOT"] = "WORKER_SLOT";
204
210
  TenantResource["EVENT"] = "EVENT";
205
- TenantResource["WORKFLOW_RUN"] = "WORKFLOW_RUN";
206
211
  TenantResource["TASK_RUN"] = "TASK_RUN";
207
212
  TenantResource["CRON"] = "CRON";
208
213
  TenantResource["SCHEDULE"] = "SCHEDULE";
@@ -240,6 +245,7 @@ var V1WebhookSourceName;
240
245
  V1WebhookSourceName["STRIPE"] = "STRIPE";
241
246
  V1WebhookSourceName["SLACK"] = "SLACK";
242
247
  V1WebhookSourceName["LINEAR"] = "LINEAR";
248
+ V1WebhookSourceName["SVIX"] = "SVIX";
243
249
  })(V1WebhookSourceName || (exports.V1WebhookSourceName = V1WebhookSourceName = {}));
244
250
  var TenantEnvironment;
245
251
  (function (TenantEnvironment) {
@@ -252,6 +258,11 @@ var TenantVersion;
252
258
  TenantVersion["V0"] = "V0";
253
259
  TenantVersion["V1"] = "V1";
254
260
  })(TenantVersion || (exports.TenantVersion = TenantVersion = {}));
261
+ var V1LogLineOrderByDirection;
262
+ (function (V1LogLineOrderByDirection) {
263
+ V1LogLineOrderByDirection["ASC"] = "ASC";
264
+ V1LogLineOrderByDirection["DESC"] = "DESC";
265
+ })(V1LogLineOrderByDirection || (exports.V1LogLineOrderByDirection = V1LogLineOrderByDirection = {}));
255
266
  var V1LogLineLevel;
256
267
  (function (V1LogLineLevel) {
257
268
  V1LogLineLevel["DEBUG"] = "DEBUG";
@@ -184,7 +184,31 @@ class V0Worker {
184
184
  return;
185
185
  }
186
186
  const run = () => __awaiter(this, void 0, void 0, function* () {
187
- return step(context);
187
+ const { middleware } = this.client.config;
188
+ if (middleware === null || middleware === void 0 ? void 0 : middleware.before) {
189
+ const hooks = Array.isArray(middleware.before) ? middleware.before : [middleware.before];
190
+ for (const hook of hooks) {
191
+ const extra = yield hook(context.input, context);
192
+ if (extra !== undefined) {
193
+ const merged = Object.assign(Object.assign({}, context.input), extra);
194
+ context.input = merged;
195
+ if (context.data && typeof context.data === 'object') {
196
+ context.data.input = merged;
197
+ }
198
+ }
199
+ }
200
+ }
201
+ let result = yield step(context);
202
+ if (middleware === null || middleware === void 0 ? void 0 : middleware.after) {
203
+ const hooks = Array.isArray(middleware.after) ? middleware.after : [middleware.after];
204
+ for (const hook of hooks) {
205
+ const extra = yield hook(result, context, context.input);
206
+ if (extra !== undefined) {
207
+ result = Object.assign(Object.assign({}, result), extra);
208
+ }
209
+ }
210
+ }
211
+ return result;
188
212
  });
189
213
  const success = (result) => __awaiter(this, void 0, void 0, function* () {
190
214
  this.logger.info(`Task run ${action.taskRunExternalId} succeeded`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -6,6 +6,7 @@ export declare enum SDKS {
6
6
  GO = 1,
7
7
  PYTHON = 2,
8
8
  TYPESCRIPT = 3,
9
+ RUBY = 4,
9
10
  UNRECOGNIZED = -1
10
11
  }
11
12
  export declare function sDKSFromJSON(object: any): SDKS;
@@ -82,7 +83,10 @@ export interface WorkerRegisterRequest {
82
83
  actions: string[];
83
84
  /** (optional) the services for this worker */
84
85
  services: string[];
85
- /** (optional) the number of slots this worker can handle */
86
+ /**
87
+ * (optional) the number of default slots this worker can handle
88
+ * deprecated: use slot_config instead
89
+ */
86
90
  slots?: number | undefined;
87
91
  /** (optional) worker labels (i.e. state or other metadata) */
88
92
  labels: {
@@ -92,11 +96,19 @@ export interface WorkerRegisterRequest {
92
96
  webhookId?: string | undefined;
93
97
  /** (optional) information regarding the runtime environment of the worker */
94
98
  runtimeInfo?: RuntimeInfo | undefined;
99
+ /** (optional) slot config for this worker (slot_type -> units) */
100
+ slotConfig: {
101
+ [key: string]: number;
102
+ };
95
103
  }
96
104
  export interface WorkerRegisterRequest_LabelsEntry {
97
105
  key: string;
98
106
  value: WorkerLabels | undefined;
99
107
  }
108
+ export interface WorkerRegisterRequest_SlotConfigEntry {
109
+ key: string;
110
+ value: number;
111
+ }
100
112
  export interface WorkerRegisterResponse {
101
113
  /** the tenant id */
102
114
  tenantId: string;
@@ -302,10 +314,16 @@ export interface ReleaseSlotRequest {
302
314
  }
303
315
  export interface ReleaseSlotResponse {
304
316
  }
317
+ export interface GetVersionRequest {
318
+ }
319
+ export interface GetVersionResponse {
320
+ version: string;
321
+ }
305
322
  export declare const WorkerLabels: MessageFns<WorkerLabels>;
306
323
  export declare const RuntimeInfo: MessageFns<RuntimeInfo>;
307
324
  export declare const WorkerRegisterRequest: MessageFns<WorkerRegisterRequest>;
308
325
  export declare const WorkerRegisterRequest_LabelsEntry: MessageFns<WorkerRegisterRequest_LabelsEntry>;
326
+ export declare const WorkerRegisterRequest_SlotConfigEntry: MessageFns<WorkerRegisterRequest_SlotConfigEntry>;
309
327
  export declare const WorkerRegisterResponse: MessageFns<WorkerRegisterResponse>;
310
328
  export declare const UpsertWorkerLabelsRequest: MessageFns<UpsertWorkerLabelsRequest>;
311
329
  export declare const UpsertWorkerLabelsRequest_LabelsEntry: MessageFns<UpsertWorkerLabelsRequest_LabelsEntry>;
@@ -330,6 +348,8 @@ export declare const RefreshTimeoutRequest: MessageFns<RefreshTimeoutRequest>;
330
348
  export declare const RefreshTimeoutResponse: MessageFns<RefreshTimeoutResponse>;
331
349
  export declare const ReleaseSlotRequest: MessageFns<ReleaseSlotRequest>;
332
350
  export declare const ReleaseSlotResponse: MessageFns<ReleaseSlotResponse>;
351
+ export declare const GetVersionRequest: MessageFns<GetVersionRequest>;
352
+ export declare const GetVersionResponse: MessageFns<GetVersionResponse>;
333
353
  export type DispatcherDefinition = typeof DispatcherDefinition;
334
354
  export declare const DispatcherDefinition: {
335
355
  readonly name: "Dispatcher";
@@ -444,6 +464,19 @@ export declare const DispatcherDefinition: {
444
464
  readonly responseStream: false;
445
465
  readonly options: {};
446
466
  };
467
+ /**
468
+ * GetVersion returns the dispatcher protocol version as a simple integer.
469
+ * SDKs use this to determine feature support (e.g. slot_config registration).
470
+ * Old engines that do not implement this RPC will return UNIMPLEMENTED.
471
+ */
472
+ readonly getVersion: {
473
+ readonly name: "GetVersion";
474
+ readonly requestType: MessageFns<GetVersionRequest>;
475
+ readonly requestStream: false;
476
+ readonly responseType: MessageFns<GetVersionResponse>;
477
+ readonly responseStream: false;
478
+ readonly options: {};
479
+ };
447
480
  };
448
481
  };
449
482
  export interface DispatcherServiceImplementation<CallContextExt = {}> {
@@ -465,6 +498,12 @@ export interface DispatcherServiceImplementation<CallContextExt = {}> {
465
498
  refreshTimeout(request: RefreshTimeoutRequest, context: CallContext & CallContextExt): Promise<DeepPartial<RefreshTimeoutResponse>>;
466
499
  releaseSlot(request: ReleaseSlotRequest, context: CallContext & CallContextExt): Promise<DeepPartial<ReleaseSlotResponse>>;
467
500
  upsertWorkerLabels(request: UpsertWorkerLabelsRequest, context: CallContext & CallContextExt): Promise<DeepPartial<UpsertWorkerLabelsResponse>>;
501
+ /**
502
+ * GetVersion returns the dispatcher protocol version as a simple integer.
503
+ * SDKs use this to determine feature support (e.g. slot_config registration).
504
+ * Old engines that do not implement this RPC will return UNIMPLEMENTED.
505
+ */
506
+ getVersion(request: GetVersionRequest, context: CallContext & CallContextExt): Promise<DeepPartial<GetVersionResponse>>;
468
507
  }
469
508
  export interface DispatcherClient<CallOptionsExt = {}> {
470
509
  register(request: DeepPartial<WorkerRegisterRequest>, options?: CallOptions & CallOptionsExt): Promise<WorkerRegisterResponse>;
@@ -485,6 +524,12 @@ export interface DispatcherClient<CallOptionsExt = {}> {
485
524
  refreshTimeout(request: DeepPartial<RefreshTimeoutRequest>, options?: CallOptions & CallOptionsExt): Promise<RefreshTimeoutResponse>;
486
525
  releaseSlot(request: DeepPartial<ReleaseSlotRequest>, options?: CallOptions & CallOptionsExt): Promise<ReleaseSlotResponse>;
487
526
  upsertWorkerLabels(request: DeepPartial<UpsertWorkerLabelsRequest>, options?: CallOptions & CallOptionsExt): Promise<UpsertWorkerLabelsResponse>;
527
+ /**
528
+ * GetVersion returns the dispatcher protocol version as a simple integer.
529
+ * SDKs use this to determine feature support (e.g. slot_config registration).
530
+ * Old engines that do not implement this RPC will return UNIMPLEMENTED.
531
+ */
532
+ getVersion(request: DeepPartial<GetVersionRequest>, options?: CallOptions & CallOptionsExt): Promise<GetVersionResponse>;
488
533
  }
489
534
  type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
490
535
  export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {