@hatchet-dev/typescript-sdk 1.2.0-alpha.1 → 1.2.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 (44) hide show
  1. package/clients/admin/admin-client.d.ts +3 -1
  2. package/clients/admin/admin-client.js +1 -1
  3. package/clients/hatchet-client/features/cron-client.d.ts +3 -0
  4. package/clients/hatchet-client/features/cron-client.js +2 -0
  5. package/clients/hatchet-client/features/schedule-client.d.ts +3 -0
  6. package/clients/hatchet-client/features/schedule-client.js +2 -0
  7. package/clients/rest/generated/data-contracts.d.ts +24 -0
  8. package/clients/worker/worker.js +1 -0
  9. package/package.json +2 -3
  10. package/protoc/dispatcher/dispatcher.d.ts +1 -0
  11. package/protoc/dispatcher/dispatcher.js +17 -1
  12. package/protoc/v1/workflows.d.ts +2 -0
  13. package/protoc/v1/workflows.js +19 -1
  14. package/protoc/workflows/workflows.d.ts +2 -0
  15. package/protoc/workflows/workflows.js +17 -1
  16. package/step.d.ts +15 -34
  17. package/step.js +25 -42
  18. package/v1/client/client.d.ts +3 -11
  19. package/v1/client/client.interface.d.ts +0 -2
  20. package/v1/client/client.js +14 -35
  21. package/v1/client/worker.js +2 -4
  22. package/v1/declaration.d.ts +26 -3
  23. package/v1/declaration.js +55 -64
  24. package/v1/examples/cancellations/run.js +4 -4
  25. package/v1/examples/priority/run.js +41 -0
  26. package/v1/examples/{middleware → priority}/worker.js +3 -8
  27. package/v1/examples/priority/workflow.d.ts +8 -0
  28. package/v1/examples/priority/workflow.js +50 -0
  29. package/v1/index.d.ts +1 -0
  30. package/v1/index.js +1 -0
  31. package/v1/task.d.ts +0 -5
  32. package/version.d.ts +1 -1
  33. package/version.js +1 -1
  34. package/v1/examples/middleware/hatchet-client.d.ts +0 -2
  35. package/v1/examples/middleware/hatchet-client.js +0 -32
  36. package/v1/examples/middleware/run.js +0 -34
  37. package/v1/examples/middleware/workflow.d.ts +0 -9
  38. package/v1/examples/middleware/workflow.js +0 -37
  39. package/v1/next/index.d.ts +0 -1
  40. package/v1/next/index.js +0 -17
  41. package/v1/next/middleware/middleware.d.ts +0 -27
  42. package/v1/next/middleware/middleware.js +0 -121
  43. /package/v1/examples/{middleware → priority}/run.d.ts +0 -0
  44. /package/v1/examples/{middleware → priority}/worker.d.ts +0 -0
@@ -13,11 +13,6 @@ import { WorkflowsClient } from './features/workflows';
13
13
  import { RunsClient } from './features/runs';
14
14
  import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } from '../types';
15
15
  import { RatelimitsClient } from './features';
16
- import { Middleware } from '../next/middleware/middleware';
17
- export interface RuntimeOpts {
18
- middleware?: Middleware[];
19
- }
20
- type Config = Partial<ClientConfig> & RuntimeOpts;
21
16
  /**
22
17
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
23
18
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -26,8 +21,6 @@ export declare class HatchetClient implements IHatchetClient {
26
21
  /** The underlying v0 client instance */
27
22
  _v0: InternalHatchetClient;
28
23
  _api: Api;
29
- private _middleware?;
30
- get middleware(): Middleware[] | undefined;
31
24
  /**
32
25
  * @deprecated v0 client will be removed in a future release, please upgrade to v1
33
26
  */
@@ -42,7 +35,7 @@ export declare class HatchetClient implements IHatchetClient {
42
35
  * @param options - Optional client options
43
36
  * @param axiosConfig - Optional Axios configuration for HTTP requests
44
37
  */
45
- constructor(config?: Config, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig);
38
+ constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig);
46
39
  /**
47
40
  * Static factory method to create a new Hatchet client instance.
48
41
  * @param config - Optional configuration for the client
@@ -50,7 +43,7 @@ export declare class HatchetClient implements IHatchetClient {
50
43
  * @param axiosConfig - Optional Axios configuration for HTTP requests
51
44
  * @returns A new Hatchet client instance
52
45
  */
53
- static init(config?: Config, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
46
+ static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): HatchetClient;
54
47
  /**
55
48
  * Creates a new workflow definition.
56
49
  * @template I - The input type for the workflow
@@ -105,7 +98,7 @@ export declare class HatchetClient implements IHatchetClient {
105
98
  * @param options - Configuration options for the workflow run
106
99
  * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
107
100
  */
108
- runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options?: RunOpts): Promise<WorkflowRunRef<O>>;
101
+ runNoWait<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options: RunOpts): WorkflowRunRef<O>;
109
102
  /**
110
103
  * @alias run
111
104
  * Triggers a workflow run and waits for the result.
@@ -219,4 +212,3 @@ export declare class HatchetClient implements IHatchetClient {
219
212
  webhooks(workflows: V0Workflow[]): import("../../clients/worker/handler").WebhookHandler;
220
213
  runRef<T extends Record<string, any> = any>(id: string): WorkflowRunRef<T>;
221
214
  }
222
- export {};
@@ -3,12 +3,10 @@ import { MetricsClient } from './features/metrics';
3
3
  import { RunsClient } from './features/runs';
4
4
  import { WorkersClient } from './features/workers';
5
5
  import { WorkflowsClient } from './features/workflows';
6
- import { Middleware } from '../next/middleware/middleware';
7
6
  export interface IHatchetClient {
8
7
  _v0: InternalHatchetClient;
9
8
  metrics: MetricsClient;
10
9
  runs: RunsClient;
11
10
  workflows: WorkflowsClient;
12
11
  workers: WorkersClient;
13
- middleware?: Middleware[];
14
12
  }
@@ -28,15 +28,11 @@ const workers_1 = require("./features/workers");
28
28
  const workflows_1 = require("./features/workflows");
29
29
  const runs_1 = require("./features/runs");
30
30
  const features_1 = require("./features");
31
- const middleware_1 = require("../next/middleware/middleware");
32
31
  /**
33
32
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
34
33
  * It provides methods for creating and executing workflows, as well as managing workers.
35
34
  */
36
35
  class HatchetClient {
37
- get middleware() {
38
- return this._middleware;
39
- }
40
36
  /**
41
37
  * @deprecated v0 client will be removed in a future release, please upgrade to v1
42
38
  */
@@ -67,9 +63,6 @@ class HatchetClient {
67
63
  this.tenantId = clientConfig.tenant_id;
68
64
  this._api = (0, rest_1.default)(clientConfig.api_url, clientConfig.token, axiosConfig);
69
65
  this._v0 = new hatchet_client_1.InternalHatchetClient(clientConfig, options, axiosConfig, this.runs);
70
- if (config === null || config === void 0 ? void 0 : config.middleware) {
71
- this._middleware = config.middleware;
72
- }
73
66
  }
74
67
  catch (e) {
75
68
  if (e instanceof zod_1.z.ZodError) {
@@ -120,29 +113,18 @@ class HatchetClient {
120
113
  * @param options - Configuration options for the workflow run
121
114
  * @returns A WorkflowRunRef containing the run ID and methods to interact with the run
122
115
  */
123
- runNoWait(workflow_1, input_1) {
124
- return __awaiter(this, arguments, void 0, function* (workflow, input, options = {}) {
125
- let name;
126
- if (typeof workflow === 'string') {
127
- name = workflow;
128
- }
129
- else if ('id' in workflow) {
130
- name = workflow.id;
131
- }
132
- else {
133
- throw new Error('unable to identify workflow');
134
- }
135
- const serializedInput = yield (0, middleware_1.serializeInput)(input, this.middleware);
136
- const runRef = this._v0.admin.runWorkflow(name, serializedInput, options);
137
- // Wrap the runRef to apply output deserialization
138
- const originalResult = runRef.result;
139
- runRef.result = () => __awaiter(this, void 0, void 0, function* () {
140
- const output = yield originalResult.call(runRef);
141
- const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, this.middleware);
142
- return deserializedOutput;
143
- });
144
- return runRef;
145
- });
116
+ runNoWait(workflow, input, options) {
117
+ let name;
118
+ if (typeof workflow === 'string') {
119
+ name = workflow;
120
+ }
121
+ else if ('id' in workflow) {
122
+ name = workflow.id;
123
+ }
124
+ else {
125
+ throw new Error('unable to identify workflow');
126
+ }
127
+ return this._v0.admin.runWorkflow(name, input, options);
146
128
  }
147
129
  /**
148
130
  * @alias run
@@ -170,11 +152,8 @@ class HatchetClient {
170
152
  */
171
153
  run(workflow_1, input_1) {
172
154
  return __awaiter(this, arguments, void 0, function* (workflow, input, options = {}) {
173
- const serializedInput = yield (0, middleware_1.serializeInput)(input, this.middleware);
174
- const runRef = yield this.runNoWait(workflow, serializedInput, options);
175
- const output = yield runRef.result();
176
- const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, this.middleware);
177
- return deserializedOutput;
155
+ const run = this.runNoWait(workflow, input, options);
156
+ return run.output;
178
157
  });
179
158
  }
180
159
  /**
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Worker = void 0;
13
13
  const declaration_1 = require("../declaration");
14
- const middleware_1 = require("../next/middleware/middleware");
15
14
  const DEFAULT_DURABLE_SLOTS = 1000;
16
15
  /**
17
16
  * HatchetWorker class for workflow execution runtime
@@ -51,14 +50,13 @@ class Worker {
51
50
  return __awaiter(this, void 0, void 0, function* () {
52
51
  return Promise.all((workflows === null || workflows === void 0 ? void 0 : workflows.map((wf) => __awaiter(this, void 0, void 0, function* () {
53
52
  if (wf instanceof declaration_1.BaseWorkflowDeclaration) {
54
- const withMiddleware = yield (0, middleware_1.bindMiddleware)(wf, this._v1);
55
53
  // TODO check if tenant is V1
56
- const register = this.nonDurable.registerWorkflowV1(withMiddleware);
54
+ const register = this.nonDurable.registerWorkflowV1(wf);
57
55
  if (wf.definition._durableTasks.length > 0) {
58
56
  if (!this.durable) {
59
57
  this.durable = yield this._v0.worker(`${this.name}-durable`, Object.assign(Object.assign({}, this.config), { maxRuns: this.config.durableSlots || DEFAULT_DURABLE_SLOTS }));
60
58
  }
61
- this.durable.registerDurableActionsV1(withMiddleware.definition);
59
+ this.durable.registerDurableActionsV1(wf.definition);
62
60
  }
63
61
  return register;
64
62
  }
@@ -7,6 +7,11 @@ import { CreateWorkflowTaskOpts, CreateOnFailureTaskOpts, TaskConcurrency, TaskF
7
7
  import { Duration } from './client/duration';
8
8
  import { MetricsClient } from './client/features/metrics';
9
9
  import { InputType, OutputType, UnknownInputType, JsonObject } from './types';
10
+ export declare enum Priority {
11
+ LOW = 1,
12
+ MEDIUM = 2,
13
+ HIGH = 3
14
+ }
10
15
  /**
11
16
  * Additional metadata that can be attached to a workflow run.
12
17
  */
@@ -16,9 +21,15 @@ type AdditionalMetadata = Record<string, string>;
16
21
  */
17
22
  export type RunOpts = {
18
23
  /**
19
- * Additional metadata to attach to the workflow run.
24
+ * (optional) additional metadata to attach to the workflow run.
20
25
  */
21
26
  additionalMetadata?: AdditionalMetadata;
27
+ /**
28
+ * (optional) the priority for the workflow run.
29
+ *
30
+ * values: Priority.LOW, Priority.MEDIUM, Priority.HIGH (1, 2, or 3 )
31
+ */
32
+ priority?: Priority;
22
33
  };
23
34
  /**
24
35
  * Helper type to safely extract output types from task results
@@ -59,6 +70,11 @@ export type CreateBaseWorkflowOpts = {
59
70
  */
60
71
  onEvents?: string[];
61
72
  concurrency?: TaskConcurrency;
73
+ /**
74
+ * (optional) the priority for the workflow.
75
+ * values: Priority.LOW, Priority.MEDIUM, Priority.HIGH (1, 2, or 3 )
76
+ */
77
+ defaultPriority?: Priority;
62
78
  };
63
79
  export type CreateTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, TaskFn<I, O>>;
64
80
  export type CreateDurableTaskWorkflowOpts<I extends InputType = UnknownInputType, O extends OutputType = void> = CreateBaseWorkflowOpts & CreateBaseTaskOpts<I, O, DurableTaskFn<I, O>>;
@@ -172,7 +188,7 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
172
188
  * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
173
189
  * @throws Error if the workflow is not bound to a Hatchet client.
174
190
  */
175
- runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): Promise<WorkflowRunRef<O>>;
191
+ runNoWait(input: I, options?: RunOpts, _standaloneTaskName?: string): WorkflowRunRef<O>;
176
192
  /**
177
193
  * @alias run
178
194
  * Triggers a workflow run and waits for the result.
@@ -301,9 +317,16 @@ export declare class WorkflowDeclaration<I extends InputType = UnknownInputType,
301
317
  export declare class TaskWorkflowDeclaration<I extends InputType = UnknownInputType, O extends OutputType = void> extends BaseWorkflowDeclaration<I, O> {
302
318
  _standalone_task_name: string;
303
319
  constructor(options: CreateTaskWorkflowOpts<I, O>, client?: IHatchetClient);
304
- runNoWait(input: I, options?: RunOpts): Promise<WorkflowRunRef<O>>;
305
320
  run(input: I, options?: RunOpts): Promise<O>;
306
321
  run(input: I[], options?: RunOpts): Promise<O[]>;
322
+ /**
323
+ * Triggers a workflow run without waiting for completion.
324
+ * @param input The input data for the workflow.
325
+ * @param options Optional configuration for this workflow run.
326
+ * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
327
+ * @throws Error if the workflow is not bound to a Hatchet client.
328
+ */
329
+ runNoWait(input: I, options?: RunOpts): WorkflowRunRef<O>;
307
330
  get taskDef(): CreateWorkflowTaskOpts<any, any>;
308
331
  }
309
332
  /**
package/v1/declaration.js CHANGED
@@ -9,12 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = void 0;
12
+ exports.TaskWorkflowDeclaration = exports.WorkflowDeclaration = exports.BaseWorkflowDeclaration = exports.Priority = void 0;
13
13
  exports.CreateTaskWorkflow = CreateTaskWorkflow;
14
14
  exports.CreateWorkflow = CreateWorkflow;
15
15
  exports.CreateDurableTaskWorkflow = CreateDurableTaskWorkflow;
16
- const middleware_1 = require("./next/middleware/middleware");
17
16
  const UNBOUND_ERR = new Error('workflow unbound to hatchet client, hint: use client.run instead');
17
+ // eslint-disable-next-line no-shadow
18
+ var Priority;
19
+ (function (Priority) {
20
+ Priority[Priority["LOW"] = 1] = "LOW";
21
+ Priority[Priority["MEDIUM"] = 2] = "MEDIUM";
22
+ Priority[Priority["HIGH"] = 3] = "HIGH";
23
+ })(Priority || (exports.Priority = Priority = {}));
18
24
  /**
19
25
  * Represents a workflow that can be executed by Hatchet.
20
26
  * @template I The input type for the workflow.
@@ -38,25 +44,14 @@ class BaseWorkflowDeclaration {
38
44
  * @throws Error if the workflow is not bound to a Hatchet client.
39
45
  */
40
46
  runNoWait(input, options, _standaloneTaskName) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (!this.client) {
43
- throw UNBOUND_ERR;
44
- }
45
- const serializedInput = yield (0, middleware_1.serializeInput)(input, this.client.middleware);
46
- const res = this.client._v0.admin.runWorkflow(this.name, serializedInput, options);
47
- if (_standaloneTaskName) {
48
- res._standalone_task_name = _standaloneTaskName;
49
- }
50
- // Wrap the result method to apply output deserialization
51
- const originalResult = res.result;
52
- res.result = () => __awaiter(this, void 0, void 0, function* () {
53
- var _a;
54
- const output = yield originalResult.call(res);
55
- const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, (_a = this.client) === null || _a === void 0 ? void 0 : _a.middleware);
56
- return deserializedOutput;
57
- });
58
- return res;
59
- });
47
+ if (!this.client) {
48
+ throw UNBOUND_ERR;
49
+ }
50
+ const res = this.client._v0.admin.runWorkflow(this.name, input, options);
51
+ if (_standaloneTaskName) {
52
+ res._standalone_task_name = _standaloneTaskName;
53
+ }
54
+ return res;
60
55
  }
61
56
  runAndWait(input, options, _standaloneTaskName) {
62
57
  return __awaiter(this, void 0, void 0, function* () {
@@ -75,16 +70,32 @@ class BaseWorkflowDeclaration {
75
70
  throw UNBOUND_ERR;
76
71
  }
77
72
  if (Array.isArray(input)) {
78
- return Promise.all(input.map((i) => this.run(i, options, _standaloneTaskName)));
73
+ let resp = [];
74
+ for (let i = 0; i < input.length; i += 500) {
75
+ const batch = input.slice(i, i + 500);
76
+ const batchResp = yield this.client._v0.admin.runWorkflows(batch.map((inp) => ({
77
+ workflowName: this.definition.name,
78
+ input: inp,
79
+ options,
80
+ })));
81
+ resp = resp.concat(batchResp);
82
+ }
83
+ const res = [];
84
+ resp.forEach((ref, index) => {
85
+ const wf = input[index].workflow;
86
+ if (wf instanceof TaskWorkflowDeclaration) {
87
+ // eslint-disable-next-line no-param-reassign
88
+ ref._standalone_task_name = wf._standalone_task_name;
89
+ }
90
+ res.push(ref.result());
91
+ });
92
+ return Promise.all(res);
79
93
  }
80
- const serializedInput = yield (0, middleware_1.serializeInput)(input, this.client.middleware);
81
- const res = this.client._v0.admin.runWorkflow(this.name, serializedInput, options);
94
+ const res = this.client._v0.admin.runWorkflow(this.definition.name, input, options);
82
95
  if (_standaloneTaskName) {
83
96
  res._standalone_task_name = _standaloneTaskName;
84
97
  }
85
- const output = yield res.result();
86
- const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, this.client.middleware);
87
- return deserializedOutput;
98
+ return res.result();
88
99
  });
89
100
  }
90
101
  /**
@@ -100,11 +111,7 @@ class BaseWorkflowDeclaration {
100
111
  if (!this.client) {
101
112
  throw UNBOUND_ERR;
102
113
  }
103
- const scheduled = this.client._v0.schedule.create(this.definition.name, {
104
- triggerAt: enqueueAt,
105
- input: input,
106
- additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
107
- });
114
+ const scheduled = this.client._v0.schedule.create(this.definition.name, Object.assign({ triggerAt: enqueueAt, input: input }, options));
108
115
  return scheduled;
109
116
  });
110
117
  }
@@ -137,12 +144,7 @@ class BaseWorkflowDeclaration {
137
144
  if (!this.client) {
138
145
  throw UNBOUND_ERR;
139
146
  }
140
- const cronDef = this.client._v0.cron.create(this.definition.name, {
141
- expression,
142
- input: input,
143
- additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata,
144
- name,
145
- });
147
+ const cronDef = this.client._v0.cron.create(this.definition.name, Object.assign(Object.assign({ expression, input: input }, options), { additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata, name }));
146
148
  return cronDef;
147
149
  });
148
150
  }
@@ -304,37 +306,26 @@ class TaskWorkflowDeclaration extends BaseWorkflowDeclaration {
304
306
  this._standalone_task_name = options.name;
305
307
  this.definition._tasks.push(Object.assign({}, options));
306
308
  }
307
- runNoWait(input, options) {
309
+ run(input, options) {
308
310
  const _super = Object.create(null, {
309
- runNoWait: { get: () => super.runNoWait }
311
+ run: { get: () => super.run }
310
312
  });
311
313
  return __awaiter(this, void 0, void 0, function* () {
312
- if (!this.client) {
313
- throw UNBOUND_ERR;
314
- }
315
- const res = yield _super.runNoWait.call(this, input, options, this._standalone_task_name);
316
- // Wrap the result method to apply output deserialization
317
- const originalResult = res.result;
318
- res.result = () => __awaiter(this, void 0, void 0, function* () {
319
- var _a;
320
- const output = yield originalResult.call(res);
321
- const deserializedOutput = yield (0, middleware_1.deserializeOutput)(output, (_a = this.client) === null || _a === void 0 ? void 0 : _a.middleware);
322
- return deserializedOutput;
323
- });
324
- return res;
314
+ return (yield _super.run.call(this, input, options, this._standalone_task_name));
325
315
  });
326
316
  }
327
- run(input, options) {
328
- return __awaiter(this, void 0, void 0, function* () {
329
- if (!this.client) {
330
- throw UNBOUND_ERR;
331
- }
332
- if (Array.isArray(input)) {
333
- return Promise.all(input.map((i) => this.run(i, options)));
334
- }
335
- const runRef = yield this.runNoWait(input, options);
336
- return runRef.result();
337
- });
317
+ /**
318
+ * Triggers a workflow run without waiting for completion.
319
+ * @param input The input data for the workflow.
320
+ * @param options Optional configuration for this workflow run.
321
+ * @returns A WorkflowRunRef containing the run ID and methods to get results and interact with the run.
322
+ * @throws Error if the workflow is not bound to a Hatchet client.
323
+ */
324
+ runNoWait(input, options) {
325
+ if (!this.client) {
326
+ throw UNBOUND_ERR;
327
+ }
328
+ return super.runNoWait(input, options, this._standalone_task_name);
338
329
  }
339
330
  get taskDef() {
340
331
  return this.definition._tasks[0];
@@ -20,8 +20,8 @@ const hatchet_client_1 = require("../hatchet-client");
20
20
  // ...
21
21
  function main() {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
- const run = yield workflow_1.cancellation.runNoWait({});
24
- const run1 = yield workflow_1.cancellation.runNoWait({});
23
+ const run = workflow_1.cancellation.runNoWait({});
24
+ const run1 = workflow_1.cancellation.runNoWait({});
25
25
  yield (0, sleep_1.default)(1000);
26
26
  yield run.cancel();
27
27
  const res = yield run.output;
@@ -32,8 +32,8 @@ function main() {
32
32
  yield run.replay();
33
33
  const resReplay = yield run.output;
34
34
  console.log(resReplay);
35
- const run2 = yield workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'abc' } });
36
- const run4 = yield workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
35
+ const run2 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'abc' } });
36
+ const run4 = workflow_1.cancellation.runNoWait({}, { additionalMetadata: { test: 'test' } });
37
37
  yield (0, sleep_1.default)(1000);
38
38
  yield hatchet_client_1.hatchet.runs.cancel({
39
39
  filters: {
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const v1_1 = require("../..");
13
+ const workflow_1 = require("./workflow");
14
+ /* eslint-disable no-console */
15
+ function main() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ console.log('running priority workflow');
19
+ // ❓ Run a Task with a Priority
20
+ const run = workflow_1.priority.run(new Date(Date.now() + 60 * 60 * 1000), { priority: v1_1.Priority.HIGH });
21
+ // !!
22
+ // ❓ Schedule and cron
23
+ const scheduled = workflow_1.priority.schedule(new Date(Date.now() + 60 * 60 * 1000), {}, { priority: v1_1.Priority.HIGH });
24
+ const delayed = workflow_1.priority.delay(60 * 60 * 1000, {}, { priority: v1_1.Priority.HIGH });
25
+ const cron = workflow_1.priority.cron(`daily-cron-${Math.random()}`, '0 0 * * *', {}, { priority: v1_1.Priority.HIGH });
26
+ // !!
27
+ const [scheduledResult, delayedResult] = yield Promise.all([scheduled, delayed]);
28
+ console.log('scheduledResult', scheduledResult);
29
+ console.log('delayedResult', delayedResult);
30
+ // !!
31
+ }
32
+ catch (e) {
33
+ console.log('error', e);
34
+ }
35
+ });
36
+ }
37
+ if (require.main === module) {
38
+ main()
39
+ .catch(console.error)
40
+ .finally(() => process.exit(0));
41
+ }
@@ -9,16 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- // Declaring a Worker
13
- const hatchet_client_1 = require("./hatchet-client");
12
+ const hatchet_client_1 = require("../hatchet-client");
14
13
  const workflow_1 = require("./workflow");
15
14
  function main() {
16
15
  return __awaiter(this, void 0, void 0, function* () {
17
- const worker = yield hatchet_client_1.hatchet.worker('withMiddleware-worker', {
18
- // 👀 Declare the workflows that the worker can execute
19
- workflows: [workflow_1.withMiddleware],
20
- // 👀 Declare the number of concurrent task runs the worker can accept
21
- slots: 100,
16
+ const worker = yield hatchet_client_1.hatchet.worker('priority-worker', {
17
+ workflows: [...workflow_1.priorityTasks],
22
18
  });
23
19
  yield worker.start();
24
20
  });
@@ -26,4 +22,3 @@ function main() {
26
22
  if (require.main === module) {
27
23
  main();
28
24
  }
29
- // !!
@@ -0,0 +1,8 @@
1
+ import { Priority } from '../..';
2
+ export declare const priority: import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
3
+ priority: Priority | undefined;
4
+ }>;
5
+ export declare const priorityWf: import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}>;
6
+ export declare const priorityTasks: (import("../..").WorkflowDeclaration<import("../..").UnknownInputType, {}> | import("../..").TaskWorkflowDeclaration<import("../..").UnknownInputType, {
7
+ priority: Priority | undefined;
8
+ }>)[];
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.priorityTasks = exports.priorityWf = exports.priority = void 0;
13
+ /* eslint-disable no-console */
14
+ const v1_1 = require("../..");
15
+ const hatchet_client_1 = require("../hatchet-client");
16
+ // ❓ Simple Task Priority
17
+ exports.priority = hatchet_client_1.hatchet.task({
18
+ name: 'priority',
19
+ defaultPriority: v1_1.Priority.MEDIUM,
20
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
21
+ return {
22
+ priority: ctx.priority(),
23
+ };
24
+ }),
25
+ });
26
+ // !!
27
+ // ❓ Task Priority in a Workflow
28
+ exports.priorityWf = hatchet_client_1.hatchet.workflow({
29
+ name: 'priorityWf',
30
+ defaultPriority: v1_1.Priority.LOW,
31
+ });
32
+ // !!
33
+ exports.priorityWf.task({
34
+ name: 'child-medium',
35
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
36
+ return {
37
+ priority: ctx.priority(),
38
+ };
39
+ }),
40
+ });
41
+ exports.priorityWf.task({
42
+ name: 'child-high',
43
+ // will inherit the default priority from the workflow
44
+ fn: (_, ctx) => __awaiter(void 0, void 0, void 0, function* () {
45
+ return {
46
+ priority: ctx.priority(),
47
+ };
48
+ }),
49
+ });
50
+ exports.priorityTasks = [exports.priority, exports.priorityWf];
package/v1/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export * from './declaration';
5
5
  export * from './conditions';
6
6
  export * from './client/duration';
7
7
  export * from './types';
8
+ export * from './task';
package/v1/index.js CHANGED
@@ -21,3 +21,4 @@ __exportStar(require("./declaration"), exports);
21
21
  __exportStar(require("./conditions"), exports);
22
22
  __exportStar(require("./client/duration"), exports);
23
23
  __exportStar(require("./types"), exports);
24
+ __exportStar(require("./task"), exports);
package/v1/task.d.ts CHANGED
@@ -3,7 +3,6 @@ import { Context, CreateStep, DurableContext } from '../step';
3
3
  import { Conditions } from './conditions';
4
4
  import { Duration } from './client/duration';
5
5
  import { InputType, OutputType, UnknownInputType } from './types';
6
- import { Middleware } from './next/middleware/middleware';
7
6
  /**
8
7
  * Options for configuring the concurrency for a task.
9
8
  */
@@ -99,10 +98,6 @@ export type CreateBaseTaskOpts<I extends InputType = UnknownInputType, O extends
99
98
  * (optional) the concurrency options for the task
100
99
  */
101
100
  concurrency?: TaskConcurrency | TaskConcurrency[];
102
- /**
103
- * (optional) the middleware for the task
104
- */
105
- middleware?: Middleware[];
106
101
  };
107
102
  export type CreateWorkflowTaskOpts<I extends InputType = UnknownInputType, O extends OutputType = void, C extends TaskFn<I, O> | DurableTaskFn<I, O> = TaskFn<I, O>> = CreateBaseTaskOpts<I, O, C> & {
108
103
  /**
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.2.0-alpha.1";
1
+ export declare const HATCHET_VERSION = "1.2.0";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HATCHET_VERSION = void 0;
4
- exports.HATCHET_VERSION = '1.2.0-alpha.1';
4
+ exports.HATCHET_VERSION = '1.2.0';
@@ -1,2 +0,0 @@
1
- import { HatchetClient } from '../../client/client';
2
- export declare const hatchet: HatchetClient;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hatchet = void 0;
4
- const client_1 = require("../../client/client");
5
- class EncodeSerializer {
6
- deserialize(input) {
7
- console.log('client-encode-deserialize', input);
8
- if (input.encoded && typeof input.encoded === 'string') {
9
- console.warn('WARNING THIS IS NOT REAL ENCRYPTION');
10
- const decoded = Buffer.from(input.encoded, 'base64').toString('utf-8');
11
- return JSON.parse(decoded);
12
- }
13
- return input;
14
- }
15
- serialize(input) {
16
- console.warn('WARNING THIS IS NOT REAL ENCRYPTION');
17
- const encoded = Buffer.from(JSON.stringify(input)).toString('base64');
18
- console.log('client-encode-serialize', input);
19
- return {
20
- encoded,
21
- };
22
- }
23
- }
24
- class EncodeMiddleware {
25
- constructor() {
26
- this.input = new EncodeSerializer();
27
- this.output = new EncodeSerializer();
28
- }
29
- }
30
- exports.hatchet = client_1.HatchetClient.init({
31
- middleware: [new EncodeMiddleware()],
32
- });