@hatchet-dev/typescript-sdk 1.6.1 → 1.6.3

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 (39) hide show
  1. package/clients/admin/admin-client.d.ts +1 -0
  2. package/clients/admin/admin-client.js +5 -11
  3. package/clients/event/event-client.js +3 -4
  4. package/clients/hatchet-client/hatchet-client.d.ts +0 -4
  5. package/clients/hatchet-client/hatchet-client.js +0 -5
  6. package/clients/worker/worker.d.ts +1 -1
  7. package/clients/worker/worker.js +5 -4
  8. package/package.json +1 -1
  9. package/step.js +3 -2
  10. package/util/apply-namespace.d.ts +1 -0
  11. package/util/apply-namespace.js +9 -0
  12. package/util/config-loader/config-loader.js +5 -2
  13. package/util/uuid.d.ts +1 -0
  14. package/util/uuid.js +7 -0
  15. package/v1/client/admin.js +3 -8
  16. package/v1/client/client.d.ts +13 -5
  17. package/v1/client/client.interface.d.ts +4 -0
  18. package/v1/client/client.js +19 -11
  19. package/{clients/hatchet-client/features/cron-client.d.ts → v1/client/features/crons.d.ts} +13 -19
  20. package/{clients/hatchet-client/features/cron-client.js → v1/client/features/crons.js} +31 -16
  21. package/v1/client/features/index.d.ts +2 -0
  22. package/v1/client/features/index.js +2 -0
  23. package/{clients/hatchet-client/features/schedule-client.d.ts → v1/client/features/schedules.d.ts} +12 -18
  24. package/{clients/hatchet-client/features/schedule-client.js → v1/client/features/schedules.js} +31 -16
  25. package/v1/client/features/workflows.d.ts +10 -3
  26. package/v1/client/features/workflows.js +43 -1
  27. package/v1/client/worker/context.d.ts +2 -2
  28. package/v1/client/worker/context.js +3 -2
  29. package/v1/client/worker/worker-internal.d.ts +2 -3
  30. package/v1/client/worker/worker-internal.js +13 -12
  31. package/v1/client/worker/worker.js +1 -1
  32. package/v1/declaration.d.ts +4 -1
  33. package/v1/declaration.js +5 -3
  34. package/v1/examples/on_event/filter.d.ts +1 -0
  35. package/v1/examples/on_event/filter.js +32 -0
  36. package/v1/examples/simple/cron.js +1 -1
  37. package/v1/examples/simple/schedule.js +3 -3
  38. package/version.d.ts +1 -1
  39. package/version.js +1 -1
@@ -186,6 +186,7 @@ export declare class AdminClient {
186
186
  * @param name the name of the workflow to schedule
187
187
  * @param options an object containing the schedules to set
188
188
  * @param input an object containing the input to the workflow
189
+ * @deprecated use hatchet.schedules.create instead
189
190
  */
190
191
  scheduleWorkflow(name: string, options?: {
191
192
  schedules?: Date[];
@@ -18,6 +18,7 @@ const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error
18
18
  const retrier_1 = require("../../util/retrier");
19
19
  const workflow_run_ref_1 = __importDefault(require("../../util/workflow-run-ref"));
20
20
  const workflows_2 = require("../../protoc/v1/workflows");
21
+ const apply_namespace_1 = require("../../util/apply-namespace");
21
22
  class AdminClient {
22
23
  constructor(config, channel, factory, api, tenantId, listenerClient, workflows) {
23
24
  this.config = config;
@@ -116,11 +117,8 @@ class AdminClient {
116
117
  * @returns the ID of the new workflow run
117
118
  */
118
119
  runWorkflow(workflowName, input, options) {
119
- let computedName = workflowName;
120
+ const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
120
121
  try {
121
- if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
122
- computedName = this.config.namespace + workflowName;
123
- }
124
122
  const inputStr = JSON.stringify(input);
125
123
  const resp = this.client.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
126
124
  ? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
@@ -140,10 +138,7 @@ class AdminClient {
140
138
  runWorkflows(workflowRuns) {
141
139
  // Prepare workflows to be triggered in bulk
142
140
  const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
143
- let computedName = workflowName;
144
- if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
145
- computedName = this.config.namespace + workflowName;
146
- }
141
+ const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
147
142
  const inputStr = JSON.stringify(input);
148
143
  return Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
149
144
  ? JSON.stringify(options.additionalMetadata)
@@ -274,13 +269,12 @@ class AdminClient {
274
269
  * @param name the name of the workflow to schedule
275
270
  * @param options an object containing the schedules to set
276
271
  * @param input an object containing the input to the workflow
272
+ * @deprecated use hatchet.schedules.create instead
277
273
  */
278
274
  scheduleWorkflow(name, options) {
279
275
  let computedName = name;
280
276
  try {
281
- if (this.config.namespace && !name.startsWith(this.config.namespace)) {
282
- computedName = this.config.namespace + name;
283
- }
277
+ computedName = (0, apply_namespace_1.applyNamespace)(name, this.config.namespace);
284
278
  let input;
285
279
  if (options === null || options === void 0 ? void 0 : options.input) {
286
280
  input = JSON.stringify(options.input);
@@ -16,6 +16,7 @@ exports.EventClient = exports.LogLevel = void 0;
16
16
  const events_1 = require("../../protoc/events/events");
17
17
  const hatchet_error_1 = __importDefault(require("../../util/errors/hatchet-error"));
18
18
  const retrier_1 = require("../../util/retrier");
19
+ const apply_namespace_1 = require("../../util/apply-namespace");
19
20
  // eslint-disable-next-line no-shadow
20
21
  var LogLevel;
21
22
  (function (LogLevel) {
@@ -34,8 +35,7 @@ class EventClient {
34
35
  this.tenantId = config.tenant_id;
35
36
  }
36
37
  push(type, input, options = {}) {
37
- var _a;
38
- const namespacedType = `${(_a = this.config.namespace) !== null && _a !== void 0 ? _a : ''}${type}`;
38
+ const namespacedType = (0, apply_namespace_1.applyNamespace)(type, this.config.namespace);
39
39
  const req = {
40
40
  key: namespacedType,
41
41
  payload: JSON.stringify(input),
@@ -56,8 +56,7 @@ class EventClient {
56
56
  }
57
57
  }
58
58
  bulkPush(type, inputs, options = {}) {
59
- var _a;
60
- const namespacedType = `${(_a = this.config.namespace) !== null && _a !== void 0 ? _a : ''}${type}`;
59
+ const namespacedType = (0, apply_namespace_1.applyNamespace)(type, this.config.namespace);
61
60
  const events = inputs.map((input) => {
62
61
  return {
63
62
  key: namespacedType,
@@ -10,8 +10,6 @@ import { RunsClient } from '../../v1';
10
10
  import { ClientConfig } from './client-config';
11
11
  import { RunListenerClient } from '../listeners/run-listener/child-listener-client';
12
12
  import { Api } from '../rest/generated/Api';
13
- import { CronClient } from './features/cron-client';
14
- import { ScheduleClient } from './features/schedule-client';
15
13
  import { DurableListenerClient } from '../listeners/durable-listener/durable-listener-client';
16
14
  export interface HatchetClientOptions {
17
15
  config_path?: string;
@@ -29,8 +27,6 @@ export declare class LegacyHatchetClient {
29
27
  tenantId: string;
30
28
  durableListener: DurableListenerClient;
31
29
  logger: Logger;
32
- cron: CronClient;
33
- schedule: ScheduleClient;
34
30
  constructor(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosOpts?: AxiosRequestConfig, runs?: RunsClient);
35
31
  static init(config?: Partial<ClientConfig>, options?: HatchetClientOptions, axiosConfig?: AxiosRequestConfig): LegacyHatchetClient;
36
32
  run(workflow: string | V0Workflow): Promise<V0Worker>;
@@ -25,8 +25,6 @@ const grpc_helpers_1 = require("../../util/grpc-helpers");
25
25
  const client_config_1 = require("./client-config");
26
26
  const child_listener_client_1 = require("../listeners/run-listener/child-listener-client");
27
27
  const rest_1 = __importDefault(require("../rest"));
28
- const cron_client_1 = require("./features/cron-client");
29
- const schedule_client_1 = require("./features/schedule-client");
30
28
  const durable_listener_client_1 = require("../listeners/durable-listener/durable-listener-client");
31
29
  class LegacyHatchetClient {
32
30
  constructor(config, options, axiosOpts, runs) {
@@ -63,9 +61,6 @@ class LegacyHatchetClient {
63
61
  this.durableListener = new durable_listener_client_1.DurableListenerClient(this.config, (0, grpc_helpers_1.channelFactory)(this.config, this.credentials), clientFactory, this.api);
64
62
  this.logger = this.config.logger('HatchetClient', this.config.log_level);
65
63
  this.logger.debug(`Initialized HatchetClient`);
66
- // Feature Clients
67
- this.cron = new cron_client_1.CronClient(this.tenantId, this.config, this.api, this.admin);
68
- this.schedule = new schedule_client_1.ScheduleClient(this.tenantId, this.config, this.api, this.admin);
69
64
  }
70
65
  static init(config, options, axiosConfig) {
71
66
  return new LegacyHatchetClient(config, options, axiosConfig);
@@ -6,7 +6,7 @@ import { Workflow } from '../../workflow';
6
6
  import { Logger } from '../../util/logger';
7
7
  import { WebhookHandler } from './handler';
8
8
  import { WebhookWorkerCreateRequest } from '../rest/generated/data-contracts';
9
- import { WorkflowDefinition } from '../../v1/declaration';
9
+ import { WorkflowDefinition } from '../../v1';
10
10
  import { V0Context, StepRunFunction } from '../../step';
11
11
  import { WorkerLabels } from '../dispatcher/dispatcher-client';
12
12
  export type ActionRegistry = Record<Action['actionId'], Function>;
@@ -27,6 +27,7 @@ const hatchet_promise_1 = __importDefault(require("../../util/hatchet-promise/ha
27
27
  const workflows_1 = require("../../protoc/workflows");
28
28
  const handler_1 = require("./handler");
29
29
  const task_1 = require("../../v1/task");
30
+ const apply_namespace_1 = require("../../util/apply-namespace");
30
31
  const step_1 = require("../../step");
31
32
  class V0Worker {
32
33
  constructor(client, options) {
@@ -36,7 +37,7 @@ class V0Worker {
36
37
  this.registeredWorkflowPromises = [];
37
38
  this.labels = {};
38
39
  this.client = client;
39
- this.name = this.client.config.namespace + options.name;
40
+ this.name = (0, apply_namespace_1.applyNamespace)(options.name, this.client.config.namespace);
40
41
  this.action_registry = {};
41
42
  this.maxRuns = options.maxRuns;
42
43
  this.labels = options.labels || {};
@@ -65,7 +66,7 @@ class V0Worker {
65
66
  getHandler(workflows) {
66
67
  // TODO v1
67
68
  for (const workflow of workflows) {
68
- const wf = Object.assign(Object.assign({}, workflow), { id: this.client.config.namespace + workflow.id });
69
+ const wf = Object.assign(Object.assign({}, workflow), { id: (0, apply_namespace_1.applyNamespace)(workflow.id, this.client.config.namespace) });
69
70
  this.registerActions(wf);
70
71
  }
71
72
  return new handler_1.WebhookHandler(this, workflows);
@@ -86,7 +87,7 @@ class V0Worker {
86
87
  registerWorkflow(initWorkflow) {
87
88
  return __awaiter(this, void 0, void 0, function* () {
88
89
  var _a, _b, _c;
89
- const workflow = Object.assign(Object.assign({}, initWorkflow), { id: (this.client.config.namespace + initWorkflow.id).toLowerCase() });
90
+ const workflow = Object.assign(Object.assign({}, initWorkflow), { id: (0, apply_namespace_1.applyNamespace)(initWorkflow.id, this.client.config.namespace).toLowerCase() });
90
91
  try {
91
92
  if (((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.key) && workflow.concurrency.expression) {
92
93
  throw new hatchet_error_1.default('Cannot have both key function and expression in workflow concurrency configuration');
@@ -125,7 +126,7 @@ class V0Worker {
125
126
  description: workflow.description,
126
127
  version: workflow.version || '',
127
128
  eventTriggers: workflow.on && workflow.on.event
128
- ? [this.client.config.namespace + workflow.on.event]
129
+ ? [(0, apply_namespace_1.applyNamespace)(workflow.on.event, this.client.config.namespace)]
129
130
  : [],
130
131
  cronTriggers: workflow.on && workflow.on.cron ? [workflow.on.cron] : [],
131
132
  scheduledTriggers: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/step.js CHANGED
@@ -58,6 +58,7 @@ const declaration_1 = require("./v1/declaration");
58
58
  const conditions_1 = require("./v1/conditions");
59
59
  const condition_1 = require("./protoc/v1/shared/condition");
60
60
  const transformer_1 = require("./v1/conditions/transformer");
61
+ const apply_namespace_1 = require("./util/apply-namespace");
61
62
  exports.CreateRateLimitSchema = z.object({
62
63
  key: z.string().optional(),
63
64
  staticKey: z.string().optional(),
@@ -386,7 +387,7 @@ class V0Context {
386
387
  else {
387
388
  workflowName = workflow.id;
388
389
  }
389
- const name = this.v0.config.namespace + workflowName;
390
+ const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v0.config.namespace);
390
391
  const opts = options || {};
391
392
  const { sticky } = opts;
392
393
  if (sticky && !this.worker.hasWorkflow(name)) {
@@ -470,7 +471,7 @@ class V0Context {
470
471
  else {
471
472
  workflowName = workflow.id;
472
473
  }
473
- const name = this.v0.config.namespace + workflowName;
474
+ const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v0.config.namespace);
474
475
  const opts = options || {};
475
476
  const { sticky } = opts;
476
477
  if (sticky && !this.worker.hasWorkflow(name)) {
@@ -0,0 +1 @@
1
+ export declare function applyNamespace(name: string, namespace?: string): string;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyNamespace = applyNamespace;
4
+ function applyNamespace(name, namespace) {
5
+ if (namespace && !name.startsWith(namespace)) {
6
+ return `${namespace}${name}`;
7
+ }
8
+ return name;
9
+ }
@@ -75,7 +75,10 @@ class ConfigLoader {
75
75
  (_x = (_w = override === null || override === void 0 ? void 0 : override.host_port) !== null && _w !== void 0 ? _w : yaml === null || yaml === void 0 ? void 0 : yaml.host_port) !== null && _x !== void 0 ? _x : this.env('HATCHET_CLIENT_HOST_PORT');
76
76
  apiUrl = (_z = (_y = override === null || override === void 0 ? void 0 : override.api_url) !== null && _y !== void 0 ? _y : yaml === null || yaml === void 0 ? void 0 : yaml.api_url) !== null && _z !== void 0 ? _z : this.env('HATCHET_CLIENT_API_URL');
77
77
  }
78
- const namespace = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.namespace) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_NAMESPACE');
78
+ let namespace = (_1 = (_0 = override === null || override === void 0 ? void 0 : override.namespace) !== null && _0 !== void 0 ? _0 : yaml === null || yaml === void 0 ? void 0 : yaml.namespace) !== null && _1 !== void 0 ? _1 : this.env('HATCHET_CLIENT_NAMESPACE');
79
+ if (namespace && !(namespace === null || namespace === void 0 ? void 0 : namespace.endsWith('_'))) {
80
+ namespace = `${namespace}_`;
81
+ }
79
82
  return {
80
83
  token: (_3 = (_2 = override === null || override === void 0 ? void 0 : override.token) !== null && _2 !== void 0 ? _2 : yaml === null || yaml === void 0 ? void 0 : yaml.token) !== null && _3 !== void 0 ? _3 : this.env('HATCHET_CLIENT_TOKEN'),
81
84
  host_port: grpcBroadcastAddress,
@@ -83,7 +86,7 @@ class ConfigLoader {
83
86
  tls_config: tlsConfig,
84
87
  log_level: (_6 = (_5 = (_4 = override === null || override === void 0 ? void 0 : override.log_level) !== null && _4 !== void 0 ? _4 : yaml === null || yaml === void 0 ? void 0 : yaml.log_level) !== null && _5 !== void 0 ? _5 : this.env('HATCHET_CLIENT_LOG_LEVEL')) !== null && _6 !== void 0 ? _6 : 'INFO',
85
88
  tenant_id: tenantId,
86
- namespace: namespace ? `${namespace}_`.toLowerCase() : '',
89
+ namespace: namespace ? `${namespace}`.toLowerCase() : '',
87
90
  };
88
91
  }
89
92
  static get default_yaml_config_path() {
package/util/uuid.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function isValidUUID(uuid: string): boolean;
package/util/uuid.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidUUID = isValidUUID;
4
+ const zod_1 = require("zod");
5
+ function isValidUUID(uuid) {
6
+ return zod_1.z.string().uuid().safeParse(uuid).success;
7
+ }
@@ -19,6 +19,7 @@ const grpc_helpers_1 = require("../../util/grpc-helpers");
19
19
  const child_listener_client_1 = require("../../clients/listeners/run-listener/child-listener-client");
20
20
  const workflows_1 = require("../../protoc/workflows");
21
21
  const batch_1 = require("../../util/batch");
22
+ const apply_namespace_1 = require("../../util/apply-namespace");
22
23
  class AdminClient {
23
24
  constructor(config, api, runs) {
24
25
  this.config = config;
@@ -38,11 +39,8 @@ class AdminClient {
38
39
  */
39
40
  runWorkflow(workflowName, input, options) {
40
41
  return __awaiter(this, void 0, void 0, function* () {
41
- let computedName = workflowName;
42
42
  try {
43
- if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
44
- computedName = this.config.namespace + workflowName;
45
- }
43
+ const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
46
44
  const inputStr = JSON.stringify(input);
47
45
  const resp = yield this.grpc.triggerWorkflow(Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
48
46
  ? JSON.stringify(options === null || options === void 0 ? void 0 : options.additionalMetadata)
@@ -69,10 +67,7 @@ class AdminClient {
69
67
  return __awaiter(this, arguments, void 0, function* (workflowRuns, batchSize = 500) {
70
68
  // Prepare workflows to be triggered in bulk
71
69
  const workflowRequests = workflowRuns.map(({ workflowName, input, options }) => {
72
- let computedName = workflowName;
73
- if (this.config.namespace && !workflowName.startsWith(this.config.namespace)) {
74
- computedName = this.config.namespace + workflowName;
75
- }
70
+ const computedName = (0, apply_namespace_1.applyNamespace)(workflowName, this.config.namespace);
76
71
  const inputStr = JSON.stringify(input);
77
72
  return Object.assign(Object.assign({ name: computedName, input: inputStr }, options), { additionalMetadata: (options === null || options === void 0 ? void 0 : options.additionalMetadata)
78
73
  ? JSON.stringify(options.additionalMetadata)
@@ -15,6 +15,8 @@ import { InputType, OutputType, UnknownInputType, StrictWorkflowOutputType } fro
15
15
  import { RatelimitsClient } from './features';
16
16
  import { AdminClient } from './admin';
17
17
  import { FiltersClient } from './features/filters';
18
+ import { ScheduleClient } from './features/schedules';
19
+ import { CronClient } from './features/crons';
18
20
  /**
19
21
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
20
22
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -124,28 +126,34 @@ export declare class HatchetClient implements IHatchetClient {
124
126
  * @returns A promise that resolves with the workflow result
125
127
  */
126
128
  run<I extends InputType = UnknownInputType, O extends OutputType = void>(workflow: BaseWorkflowDeclaration<I, O> | string | V0Workflow, input: I, options?: RunOpts): Promise<O>;
129
+ private _crons;
127
130
  /**
128
131
  * Get the cron client for creating and managing cron workflow runs
129
132
  * @returns A cron client instance
130
133
  */
131
- get crons(): import("../../clients/hatchet-client/features/cron-client").CronClient;
134
+ get crons(): CronClient;
132
135
  /**
133
136
  * Get the cron client for creating and managing cron workflow runs
134
137
  * @returns A cron client instance
135
138
  * @deprecated use client.crons instead
136
139
  */
137
- get cron(): import("../../clients/hatchet-client/features/cron-client").CronClient;
140
+ get cron(): CronClient;
141
+ private _scheduled;
138
142
  /**
139
143
  * Get the schedules client for creating and managing scheduled workflow runs
140
144
  * @returns A schedules client instance
141
145
  */
142
- get schedules(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
146
+ get scheduled(): ScheduleClient;
143
147
  /**
144
148
  * Get the schedule client for creating and managing scheduled workflow runs
145
149
  * @returns A schedule client instance
146
- * @deprecated use client.schedules instead
150
+ * @deprecated use client.scheduled instead
147
151
  */
148
- get schedule(): import("../../clients/hatchet-client/features/schedule-client").ScheduleClient;
152
+ get schedule(): ScheduleClient;
153
+ /**
154
+ * @alias scheduled
155
+ */
156
+ get schedules(): ScheduleClient;
149
157
  /**
150
158
  * Get the event client for creating and managing event workflow runs
151
159
  * @returns A event client instance
@@ -4,11 +4,15 @@ import { RunsClient } from './features/runs';
4
4
  import { WorkersClient } from './features/workers';
5
5
  import { WorkflowsClient } from './features/workflows';
6
6
  import { AdminClient } from './admin';
7
+ import { ScheduleClient } from './features/schedules';
8
+ import { CronClient } from './features/crons';
7
9
  export interface IHatchetClient {
8
10
  _v0: LegacyHatchetClient;
9
11
  metrics: MetricsClient;
10
12
  runs: RunsClient;
11
13
  workflows: WorkflowsClient;
12
14
  workers: WorkersClient;
15
+ scheduled: ScheduleClient;
16
+ crons: CronClient;
13
17
  admin: AdminClient;
14
18
  }
@@ -30,6 +30,8 @@ const runs_1 = require("./features/runs");
30
30
  const features_1 = require("./features");
31
31
  const admin_1 = require("./admin");
32
32
  const filters_1 = require("./features/filters");
33
+ const schedules_1 = require("./features/schedules");
34
+ const crons_1 = require("./features/crons");
33
35
  /**
34
36
  * HatchetV1 implements the main client interface for interacting with the Hatchet workflow engine.
35
37
  * It provides methods for creating and executing workflows, as well as managing workers.
@@ -62,12 +64,6 @@ class HatchetClient {
62
64
  logConstructor = hatchet_logger_1.DEFAULT_LOGGER;
63
65
  }
64
66
  const clientConfig = Object.assign(Object.assign({}, valid), { logger: logConstructor });
65
- // FIXME: Remove this once we have a proper namespace validation
66
- if (clientConfig.namespace) {
67
- clientConfig.namespace = clientConfig.namespace.endsWith('_')
68
- ? clientConfig.namespace.slice(0, -1)
69
- : clientConfig.namespace;
70
- }
71
67
  this._config = clientConfig;
72
68
  this.tenantId = clientConfig.tenant_id;
73
69
  this._api = (0, rest_1.default)(clientConfig.api_url, clientConfig.token, axiosConfig);
@@ -175,7 +171,10 @@ class HatchetClient {
175
171
  * @returns A cron client instance
176
172
  */
177
173
  get crons() {
178
- return this._v0.cron;
174
+ if (!this._crons) {
175
+ this._crons = new crons_1.CronClient(this);
176
+ }
177
+ return this._crons;
179
178
  }
180
179
  /**
181
180
  * Get the cron client for creating and managing cron workflow runs
@@ -189,16 +188,25 @@ class HatchetClient {
189
188
  * Get the schedules client for creating and managing scheduled workflow runs
190
189
  * @returns A schedules client instance
191
190
  */
192
- get schedules() {
193
- return this._v0.schedule;
191
+ get scheduled() {
192
+ if (!this._scheduled) {
193
+ this._scheduled = new schedules_1.ScheduleClient(this);
194
+ }
195
+ return this._scheduled;
194
196
  }
195
197
  /**
196
198
  * Get the schedule client for creating and managing scheduled workflow runs
197
199
  * @returns A schedule client instance
198
- * @deprecated use client.schedules instead
200
+ * @deprecated use client.scheduled instead
199
201
  */
200
202
  get schedule() {
201
- return this.schedules;
203
+ return this.scheduled;
204
+ }
205
+ /**
206
+ * @alias scheduled
207
+ */
208
+ get schedules() {
209
+ return this.scheduled;
202
210
  }
203
211
  /**
204
212
  * Get the event client for creating and managing event workflow runs
@@ -1,9 +1,9 @@
1
- import { AdminClient } from '../../admin';
2
- import { Api } from '../../rest';
3
- import { CronWorkflows, CronWorkflowsList } from '../../rest/generated/data-contracts';
1
+ import { CronWorkflows, CronWorkflowsList } from '../../../clients/rest/generated/data-contracts';
4
2
  import { z } from 'zod';
5
3
  import { Workflow } from '../../../workflow';
6
- import { ClientConfig } from '../client-config';
4
+ import { BaseWorkflowDeclaration } from '../..';
5
+ import { HatchetClient } from '../client';
6
+ import { WorkflowsClient } from './workflows';
7
7
  /**
8
8
  * Schema for creating a Cron Trigger.
9
9
  */
@@ -34,19 +34,11 @@ export type CreateCronInput = z.infer<typeof CreateCronTriggerSchema>;
34
34
  * Client for managing Cron Triggers.
35
35
  */
36
36
  export declare class CronClient {
37
- private readonly tenantId;
38
- private readonly config;
39
- private readonly api;
40
- private readonly adminClient;
41
- private logger;
42
- /**
43
- * Initializes a new instance of CronClient.
44
- * @param tenantId - The tenant identifier.
45
- * @param config - Client configuration settings.
46
- * @param api - API instance for REST interactions.
47
- * @param adminClient - Admin client for administrative operations.
48
- */
49
- constructor(tenantId: string, config: ClientConfig, api: Api, adminClient: AdminClient);
37
+ api: HatchetClient['api'];
38
+ tenantId: string;
39
+ workflows: WorkflowsClient;
40
+ namespace: string | undefined;
41
+ constructor(client: HatchetClient);
50
42
  /**
51
43
  * Retrieves the Cron ID from a CronWorkflows object or a string.
52
44
  * @param cron - The CronWorkflows object or Cron ID as a string.
@@ -60,7 +52,7 @@ export declare class CronClient {
60
52
  * @returns A promise that resolves to the created CronWorkflows object.
61
53
  * @throws Will throw an error if the input is invalid or the API call fails.
62
54
  */
63
- create(workflow: string | Workflow, cron: CreateCronInput): Promise<CronWorkflows>;
55
+ create(workflow: string | Workflow | BaseWorkflowDeclaration<any, any>, cron: CreateCronInput): Promise<CronWorkflows>;
64
56
  /**
65
57
  * Deletes an existing Cron Trigger.
66
58
  * @param cron - The Cron Trigger ID as a string or CronWorkflows object.
@@ -72,7 +64,9 @@ export declare class CronClient {
72
64
  * @param query - Query parameters for listing Cron Triggers.
73
65
  * @returns A promise that resolves to a CronWorkflowsList object.
74
66
  */
75
- list(query: Parameters<typeof this.api.cronWorkflowList>[1]): Promise<CronWorkflowsList>;
67
+ list(query: Parameters<typeof this.api.cronWorkflowList>[1] & {
68
+ workflow?: string | Workflow | BaseWorkflowDeclaration<any, any>;
69
+ }): Promise<CronWorkflowsList>;
76
70
  /**
77
71
  * Retrieves a specific Cron Trigger by its ID.
78
72
  * @param cron - The Cron Trigger ID as a string or CronWorkflows object.
@@ -8,10 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.CronClient = exports.CreateCronTriggerSchema = void 0;
13
24
  const zod_1 = require("zod");
14
25
  const axios_1 = require("axios");
26
+ const uuid_1 = require("../../../util/uuid");
27
+ const apply_namespace_1 = require("../../../util/apply-namespace");
28
+ const workflows_1 = require("./workflows");
15
29
  /**
16
30
  * Schema for creating a Cron Trigger.
17
31
  */
@@ -26,19 +40,11 @@ exports.CreateCronTriggerSchema = zod_1.z.object({
26
40
  * Client for managing Cron Triggers.
27
41
  */
28
42
  class CronClient {
29
- /**
30
- * Initializes a new instance of CronClient.
31
- * @param tenantId - The tenant identifier.
32
- * @param config - Client configuration settings.
33
- * @param api - API instance for REST interactions.
34
- * @param adminClient - Admin client for administrative operations.
35
- */
36
- constructor(tenantId, config, api, adminClient) {
37
- this.tenantId = tenantId;
38
- this.config = config;
39
- this.api = api;
40
- this.adminClient = adminClient;
41
- this.logger = config.logger('Cron', this.config.log_level);
43
+ constructor(client) {
44
+ this.api = client.api;
45
+ this.tenantId = client.tenantId;
46
+ this.workflows = new workflows_1.WorkflowsClient(client);
47
+ this.namespace = client.config.namespace;
42
48
  }
43
49
  /**
44
50
  * Retrieves the Cron ID from a CronWorkflows object or a string.
@@ -46,7 +52,11 @@ class CronClient {
46
52
  * @returns The Cron ID as a string.
47
53
  */
48
54
  getCronId(cron) {
49
- return typeof cron === 'string' ? cron : cron.metadata.id;
55
+ const str = typeof cron === 'string' ? cron : cron.metadata.id;
56
+ if (!(0, uuid_1.isValidUUID)(str)) {
57
+ throw new Error('Invalid cron ID: must be a valid UUID');
58
+ }
59
+ return str;
50
60
  }
51
61
  /**
52
62
  * Creates a new Cron workflow.
@@ -58,7 +68,7 @@ class CronClient {
58
68
  create(workflow, cron) {
59
69
  return __awaiter(this, void 0, void 0, function* () {
60
70
  var _a, _b, _c;
61
- const workflowId = typeof workflow === 'string' ? workflow : workflow.id;
71
+ const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace);
62
72
  // Validate cron input with zod schema
63
73
  try {
64
74
  const parsedCron = exports.CreateCronTriggerSchema.parse(cron);
@@ -100,7 +110,12 @@ class CronClient {
100
110
  */
101
111
  list(query) {
102
112
  return __awaiter(this, void 0, void 0, function* () {
103
- const response = yield this.api.cronWorkflowList(this.tenantId, query);
113
+ const { workflow } = query, rest = __rest(query, ["workflow"]);
114
+ if (workflow) {
115
+ const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace));
116
+ rest.workflowId = workflowId;
117
+ }
118
+ const response = yield this.api.cronWorkflowList(this.tenantId, rest);
104
119
  return response.data;
105
120
  });
106
121
  }
@@ -1,5 +1,7 @@
1
+ export * from './crons';
1
2
  export * from './metrics';
2
3
  export * from './ratelimits';
3
4
  export * from './runs';
4
5
  export * from './workers';
5
6
  export * from './workflows';
7
+ export * from './schedules';
@@ -14,8 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./crons"), exports);
17
18
  __exportStar(require("./metrics"), exports);
18
19
  __exportStar(require("./ratelimits"), exports);
19
20
  __exportStar(require("./runs"), exports);
20
21
  __exportStar(require("./workers"), exports);
21
22
  __exportStar(require("./workflows"), exports);
23
+ __exportStar(require("./schedules"), exports);
@@ -1,9 +1,9 @@
1
- import { AdminClient } from '../../admin';
2
- import { Api } from '../../rest';
3
- import { ScheduledWorkflows, ScheduledWorkflowsList } from '../../rest/generated/data-contracts';
1
+ import { ScheduledWorkflows, ScheduledWorkflowsList } from '../../../clients/rest/generated/data-contracts';
4
2
  import { z } from 'zod';
5
3
  import { Workflow } from '../../../workflow';
6
- import { ClientConfig } from '../client-config';
4
+ import { BaseWorkflowDeclaration, WorkflowDefinition } from '../..';
5
+ import { HatchetClient } from '../client';
6
+ import { WorkflowsClient } from './workflows';
7
7
  /**
8
8
  * Schema for creating a Scheduled Run Trigger.
9
9
  */
@@ -31,19 +31,11 @@ export type CreateScheduledRunInput = z.infer<typeof CreateScheduledRunTriggerSc
31
31
  * Client for managing Scheduled Runs.
32
32
  */
33
33
  export declare class ScheduleClient {
34
- private readonly tenantId;
35
- private readonly config;
36
- private readonly api;
37
- private readonly adminClient;
38
- private logger;
39
- /**
40
- * Initializes a new instance of ScheduleClient.
41
- * @param tenantId - The tenant identifier.
42
- * @param config - Client configuration settings.
43
- * @param api - API instance for REST interactions.
44
- * @param adminClient - Admin client for administrative operations.
45
- */
46
- constructor(tenantId: string, config: ClientConfig, api: Api, adminClient: AdminClient);
34
+ api: HatchetClient['api'];
35
+ tenantId: string;
36
+ workflows: WorkflowsClient;
37
+ namespace: string | undefined;
38
+ constructor(client: HatchetClient);
47
39
  /**
48
40
  * Retrieves the Scheduled Run ID from a ScheduledRun object or a string.
49
41
  * @param scheduledRun - The ScheduledRun object or Scheduled Run ID as a string.
@@ -69,7 +61,9 @@ export declare class ScheduleClient {
69
61
  * @param query - Query parameters for listing Scheduled Runs.
70
62
  * @returns A promise that resolves to a ScheduledWorkflowsList object.
71
63
  */
72
- list(query: Parameters<typeof this.api.workflowScheduledList>[1]): Promise<ScheduledWorkflowsList>;
64
+ list(query: Parameters<typeof this.api.workflowScheduledList>[1] & {
65
+ workflow?: string | Workflow | WorkflowDefinition | BaseWorkflowDeclaration<any, any>;
66
+ }): Promise<ScheduledWorkflowsList>;
73
67
  /**
74
68
  * Retrieves a specific Scheduled Run by its ID.
75
69
  * @param scheduledRun - The Scheduled Run ID as a string or ScheduledWorkflows object.
@@ -8,10 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.ScheduleClient = exports.CreateScheduledRunTriggerSchema = void 0;
13
24
  const zod_1 = require("zod");
14
25
  const axios_1 = require("axios");
26
+ const uuid_1 = require("../../../util/uuid");
27
+ const apply_namespace_1 = require("../../../util/apply-namespace");
28
+ const workflows_1 = require("./workflows");
15
29
  /**
16
30
  * Schema for creating a Scheduled Run Trigger.
17
31
  */
@@ -25,19 +39,11 @@ exports.CreateScheduledRunTriggerSchema = zod_1.z.object({
25
39
  * Client for managing Scheduled Runs.
26
40
  */
27
41
  class ScheduleClient {
28
- /**
29
- * Initializes a new instance of ScheduleClient.
30
- * @param tenantId - The tenant identifier.
31
- * @param config - Client configuration settings.
32
- * @param api - API instance for REST interactions.
33
- * @param adminClient - Admin client for administrative operations.
34
- */
35
- constructor(tenantId, config, api, adminClient) {
36
- this.tenantId = tenantId;
37
- this.config = config;
38
- this.api = api;
39
- this.adminClient = adminClient;
40
- this.logger = config.logger('Scheduled Run', this.config.log_level);
42
+ constructor(client) {
43
+ this.api = client.api;
44
+ this.tenantId = client.tenantId;
45
+ this.workflows = new workflows_1.WorkflowsClient(client);
46
+ this.namespace = client.config.namespace;
41
47
  }
42
48
  /**
43
49
  * Retrieves the Scheduled Run ID from a ScheduledRun object or a string.
@@ -45,7 +51,11 @@ class ScheduleClient {
45
51
  * @returns The Scheduled Run ID as a string.
46
52
  */
47
53
  getScheduledRunId(scheduledRun) {
48
- return typeof scheduledRun === 'string' ? scheduledRun : scheduledRun.metadata.id;
54
+ const str = typeof scheduledRun === 'string' ? scheduledRun : scheduledRun.metadata.id;
55
+ if (!(0, uuid_1.isValidUUID)(str)) {
56
+ throw new Error('Invalid scheduled run ID: must be a valid UUID');
57
+ }
58
+ return str;
49
59
  }
50
60
  /**
51
61
  * Creates a new Scheduled Run.
@@ -57,7 +67,7 @@ class ScheduleClient {
57
67
  create(workflow, cron) {
58
68
  return __awaiter(this, void 0, void 0, function* () {
59
69
  var _a, _b, _c;
60
- const workflowId = typeof workflow === 'string' ? workflow : workflow.id;
70
+ const workflowId = (0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace);
61
71
  // Validate cron input with zod schema
62
72
  try {
63
73
  const parsedCron = exports.CreateScheduledRunTriggerSchema.parse(cron);
@@ -98,7 +108,12 @@ class ScheduleClient {
98
108
  */
99
109
  list(query) {
100
110
  return __awaiter(this, void 0, void 0, function* () {
101
- const response = yield this.api.workflowScheduledList(this.tenantId, query);
111
+ const { workflow } = query, rest = __rest(query, ["workflow"]);
112
+ if (workflow) {
113
+ const workflowId = yield this.workflows.getWorkflowIdFromName((0, apply_namespace_1.applyNamespace)((0, workflows_1.workflowNameString)(workflow), this.namespace));
114
+ rest.workflowId = workflowId;
115
+ }
116
+ const response = yield this.api.workflowScheduledList(this.tenantId, rest);
102
117
  return response.data;
103
118
  });
104
119
  }
@@ -1,7 +1,7 @@
1
1
  import { Workflow } from '../../../workflow';
2
- import { BaseWorkflowDeclaration } from '../..';
2
+ import { BaseWorkflowDeclaration, WorkflowDefinition } from '../..';
3
3
  import { HatchetClient } from '../client';
4
- export declare const workflowNameString: (workflow: string | Workflow | BaseWorkflowDeclaration<any, any>) => string;
4
+ export declare const workflowNameString: (workflow: string | Workflow | WorkflowDefinition | BaseWorkflowDeclaration<any, any>) => string;
5
5
  /**
6
6
  * WorkflowsClient is used to list and manage workflows
7
7
  */
@@ -11,7 +11,14 @@ export declare class WorkflowsClient {
11
11
  private workflowCache;
12
12
  private cacheTTL;
13
13
  constructor(client: HatchetClient, cacheTTL?: number);
14
- get(workflow: string | BaseWorkflowDeclaration<any, any> | Workflow): Promise<any>;
14
+ /**
15
+ * Gets the workflow ID from a workflow name, ID, or object.
16
+ * If the input is not a valid UUID, it will look up the workflow by name.
17
+ * @param workflow - The workflow name, ID, or object.
18
+ * @returns The workflow ID as a string.
19
+ */
20
+ getWorkflowIdFromName(workflow: string | Workflow | WorkflowDefinition | BaseWorkflowDeclaration<any, any>): Promise<string>;
21
+ get(workflow: string | BaseWorkflowDeclaration<any, any> | Workflow): Promise<import("../../../clients/rest/generated/data-contracts").Workflow>;
15
22
  list(opts?: Parameters<typeof this.api.workflowList>[1]): Promise<import("../../../clients/rest/generated/data-contracts").WorkflowList>;
16
23
  delete(workflow: string | BaseWorkflowDeclaration<any, any> | Workflow): Promise<void>;
17
24
  }
@@ -10,7 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.WorkflowsClient = exports.workflowNameString = void 0;
13
- const workflowNameString = (workflow) => (typeof workflow === 'string' ? workflow : workflow.id);
13
+ const uuid_1 = require("../../../util/uuid");
14
+ const workflowNameString = (workflow) => {
15
+ if (typeof workflow === 'string') {
16
+ return workflow;
17
+ }
18
+ if (typeof workflow === 'object' && 'id' in workflow) {
19
+ return workflow.id;
20
+ }
21
+ return workflow.name;
22
+ };
14
23
  exports.workflowNameString = workflowNameString;
15
24
  /**
16
25
  * WorkflowsClient is used to list and manage workflows
@@ -28,6 +37,39 @@ class WorkflowsClient {
28
37
  this.cacheTTL = cacheTTL;
29
38
  }
30
39
  }
40
+ /**
41
+ * Gets the workflow ID from a workflow name, ID, or object.
42
+ * If the input is not a valid UUID, it will look up the workflow by name.
43
+ * @param workflow - The workflow name, ID, or object.
44
+ * @returns The workflow ID as a string.
45
+ */
46
+ getWorkflowIdFromName(workflow) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const str = (() => {
49
+ if (typeof workflow === 'string') {
50
+ return workflow;
51
+ }
52
+ if (typeof workflow === 'object' && 'name' in workflow) {
53
+ return workflow.name;
54
+ }
55
+ if (typeof workflow === 'object' && 'id' in workflow) {
56
+ if (!workflow.id) {
57
+ throw new Error('Workflow ID is required');
58
+ }
59
+ return workflow.id;
60
+ }
61
+ throw new Error('Invalid workflow: must be a string, Workflow object, or WorkflowDefinition object');
62
+ })();
63
+ if (!(0, uuid_1.isValidUUID)(str)) {
64
+ const wf = yield this.get(str);
65
+ if (!wf) {
66
+ throw new Error('Invalid workflow ID: must be a valid UUID');
67
+ }
68
+ return wf.metadata.id;
69
+ }
70
+ return str;
71
+ });
72
+ }
31
73
  get(workflow) {
32
74
  return __awaiter(this, void 0, void 0, function* () {
33
75
  // Get workflow name string
@@ -4,7 +4,7 @@ import { Action } from '../../../clients/dispatcher/action-listener';
4
4
  import { Logger, LogLevel } from '../../../util/logger';
5
5
  import WorkflowRunRef from '../../../util/workflow-run-ref';
6
6
  import { Conditions } from '../../conditions';
7
- import { CreateWorkflowTaskOpts } from '../../task';
7
+ import { CreateWorkflowDurableTaskOpts, CreateWorkflowTaskOpts } from '../../task';
8
8
  import { OutputType } from '../../types';
9
9
  import { Workflow } from '../../../workflow';
10
10
  import { HatchetClient } from '../..';
@@ -48,7 +48,7 @@ export declare class Context<T, K = {}> {
48
48
  * @returns The output of the specified parent task.
49
49
  * @throws An error if the task output is not found.
50
50
  */
51
- parentOutput<L extends OutputType>(parentTask: CreateWorkflowTaskOpts<any, L> | string): Promise<L>;
51
+ parentOutput<L extends OutputType>(parentTask: CreateWorkflowTaskOpts<any, L> | CreateWorkflowDurableTaskOpts<any, L> | string): Promise<L>;
52
52
  /**
53
53
  * Returns errors from any task runs in the workflow.
54
54
  * @returns A record mapping task names to error messages.
@@ -22,6 +22,7 @@ const conditions_1 = require("../../conditions");
22
22
  const transformer_1 = require("../../conditions/transformer");
23
23
  const condition_1 = require("../../../protoc/v1/shared/condition");
24
24
  const step_1 = require("../../../step");
25
+ const apply_namespace_1 = require("../../../util/apply-namespace");
25
26
  class Context {
26
27
  constructor(action, v1, worker) {
27
28
  // @deprecated use ctx.abortController instead
@@ -458,7 +459,7 @@ class Context {
458
459
  else {
459
460
  workflowName = workflow.id;
460
461
  }
461
- const name = this.v1.config.namespace + workflowName;
462
+ const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v1.config.namespace);
462
463
  const opts = options || {};
463
464
  const { sticky } = opts;
464
465
  if (sticky && !this.worker.hasWorkflow(name)) {
@@ -515,7 +516,7 @@ class Context {
515
516
  else {
516
517
  workflowName = workflow.id;
517
518
  }
518
- const name = this.v1.config.namespace + workflowName;
519
+ const name = (0, apply_namespace_1.applyNamespace)(workflowName, this.v1.config.namespace);
519
520
  const opts = options || {};
520
521
  const { sticky } = opts;
521
522
  if (sticky && !this.worker.hasWorkflow(name)) {
@@ -4,8 +4,7 @@ import HatchetPromise from '../../../util/hatchet-promise/hatchet-promise';
4
4
  import { Workflow } from '../../../workflow';
5
5
  import { Logger } from '../../../util/logger';
6
6
  import { WebhookWorkerCreateRequest } from '../../../clients/rest/generated/data-contracts';
7
- import { BaseWorkflowDeclaration, WorkflowDefinition } from '../../declaration';
8
- import { HatchetClient } from '../..';
7
+ import { BaseWorkflowDeclaration, WorkflowDefinition, HatchetClient } from '../..';
9
8
  import { WorkerLabels } from '../../../clients/dispatcher/dispatcher-client';
10
9
  import { StepRunFunction } from '../../../step';
11
10
  import { Context } from './context';
@@ -46,7 +45,7 @@ export declare class V1Worker {
46
45
  register_workflow(initWorkflow: Workflow): Promise<void>;
47
46
  registerDurableActionsV1(workflow: WorkflowDefinition): void;
48
47
  private registerActionsV1;
49
- registerWorkflowV1(initWorkflow: BaseWorkflowDeclaration<any, any>): Promise<void>;
48
+ registerWorkflowV1(initWorkflow: BaseWorkflowDeclaration<any, any>, durable?: boolean): Promise<void>;
50
49
  registerWorkflow(initWorkflow: Workflow): Promise<void>;
51
50
  registerAction<T, K>(actionId: string, action: StepRunFunction<T, K>): void;
52
51
  handleStartStepRun(action: Action): Promise<void>;
@@ -29,6 +29,7 @@ const workflows_1 = require("../../../protoc/workflows");
29
29
  const task_1 = require("../../task");
30
30
  const transformer_1 = require("../../conditions/transformer");
31
31
  const step_1 = require("../../../step");
32
+ const apply_namespace_1 = require("../../../util/apply-namespace");
32
33
  const context_1 = require("./context");
33
34
  class V1Worker {
34
35
  constructor(client, options) {
@@ -38,7 +39,7 @@ class V1Worker {
38
39
  this.registeredWorkflowPromises = [];
39
40
  this.labels = {};
40
41
  this.client = client;
41
- this.name = this.client.config.namespace + options.name;
42
+ this.name = (0, apply_namespace_1.applyNamespace)(options.name, this.client.config.namespace);
42
43
  this.action_registry = {};
43
44
  this.maxRuns = options.maxRuns;
44
45
  this.labels = options.labels || {};
@@ -113,15 +114,15 @@ class V1Worker {
113
114
  : {};
114
115
  this.action_registry = Object.assign(Object.assign(Object.assign({}, this.action_registry), newActions), onFailureAction);
115
116
  }
116
- registerWorkflowV1(initWorkflow) {
117
- return __awaiter(this, void 0, void 0, function* () {
117
+ registerWorkflowV1(initWorkflow_1) {
118
+ return __awaiter(this, arguments, void 0, function* (initWorkflow, durable = false) {
118
119
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
119
120
  // patch the namespace
120
- const workflow = Object.assign(Object.assign({}, initWorkflow.definition), { name: (this.client.config.namespace + initWorkflow.definition.name).toLowerCase() });
121
+ const workflow = Object.assign(Object.assign({}, initWorkflow.definition), { name: (0, apply_namespace_1.applyNamespace)(initWorkflow.definition.name, this.client.config.namespace).toLowerCase() });
121
122
  try {
122
123
  const { concurrency } = workflow;
123
124
  let onFailureTask;
124
- if (workflow.onFailure && typeof workflow.onFailure === 'function') {
125
+ if (!durable && workflow.onFailure && typeof workflow.onFailure === 'function') {
125
126
  onFailureTask = {
126
127
  readableId: 'on-failure-task',
127
128
  action: onFailureTaskName(workflow),
@@ -134,7 +135,7 @@ class V1Worker {
134
135
  concurrency: [],
135
136
  };
136
137
  }
137
- if (workflow.onFailure && typeof workflow.onFailure === 'object') {
138
+ if (!durable && workflow.onFailure && typeof workflow.onFailure === 'object') {
138
139
  const onFailure = workflow.onFailure;
139
140
  onFailureTask = {
140
141
  readableId: 'on-failure-task',
@@ -152,8 +153,8 @@ class V1Worker {
152
153
  };
153
154
  }
154
155
  let onSuccessTask;
155
- if (workflow.onSuccess && typeof workflow.onSuccess === 'function') {
156
- const parents = getLeaves(workflow._tasks);
156
+ if (!durable && workflow.onSuccess && typeof workflow.onSuccess === 'function') {
157
+ const parents = getLeaves([...workflow._tasks, ...workflow._durableTasks]);
157
158
  onSuccessTask = {
158
159
  name: 'on-success-task',
159
160
  fn: workflow.onSuccess,
@@ -165,9 +166,9 @@ class V1Worker {
165
166
  concurrency: [],
166
167
  };
167
168
  }
168
- if (workflow.onSuccess && typeof workflow.onSuccess === 'object') {
169
+ if (!durable && workflow.onSuccess && typeof workflow.onSuccess === 'object') {
169
170
  const onSuccess = workflow.onSuccess;
170
- const parents = getLeaves(workflow._tasks);
171
+ const parents = getLeaves([...workflow._tasks, ...workflow._durableTasks]);
171
172
  onSuccessTask = {
172
173
  name: 'on-success-task',
173
174
  fn: onSuccess.fn,
@@ -253,7 +254,7 @@ class V1Worker {
253
254
  registerWorkflow(initWorkflow) {
254
255
  return __awaiter(this, void 0, void 0, function* () {
255
256
  var _a, _b, _c;
256
- const workflow = Object.assign(Object.assign({}, initWorkflow), { id: (this.client.config.namespace + initWorkflow.id).toLowerCase() });
257
+ const workflow = Object.assign(Object.assign({}, initWorkflow), { id: (0, apply_namespace_1.applyNamespace)(initWorkflow.id, this.client.config.namespace).toLowerCase() });
257
258
  try {
258
259
  if (((_a = workflow.concurrency) === null || _a === void 0 ? void 0 : _a.key) && workflow.concurrency.expression) {
259
260
  throw new hatchet_error_1.default('Cannot have both key function and expression in workflow concurrency configuration');
@@ -292,7 +293,7 @@ class V1Worker {
292
293
  description: workflow.description,
293
294
  version: workflow.version || '',
294
295
  eventTriggers: workflow.on && workflow.on.event
295
- ? [this.client.config.namespace + workflow.on.event]
296
+ ? [(0, apply_namespace_1.applyNamespace)(workflow.on.event, this.client.config.namespace)]
296
297
  : [],
297
298
  cronTriggers: workflow.on && workflow.on.cron ? [workflow.on.cron] : [],
298
299
  scheduledTriggers: [],
@@ -58,7 +58,7 @@ class Worker {
58
58
  if (!this.durable) {
59
59
  const opts = Object.assign(Object.assign({ name: `${this.name}-durable` }, this.config), { maxRuns: this.config.durableSlots || DEFAULT_DURABLE_SLOTS });
60
60
  this.durable = new worker_internal_1.V1Worker(this._v1, opts);
61
- yield this.durable.registerWorkflowV1(wf);
61
+ yield this.durable.registerWorkflowV1(wf, true);
62
62
  }
63
63
  this.durable.registerDurableActionsV1(wf.definition);
64
64
  }
@@ -260,7 +260,10 @@ export declare class BaseWorkflowDeclaration<I extends InputType = UnknownInputT
260
260
  * @returns A promise that resolves with the workflow state.
261
261
  * @throws Error if the workflow is not bound to a Hatchet client.
262
262
  */
263
- get(): Promise<any>;
263
+ get(): Promise<import("../clients/rest/generated/data-contracts").Workflow>;
264
+ /**
265
+ * @deprecated use definition.name instead
266
+ */
264
267
  get id(): string;
265
268
  /**
266
269
  * Get the friendly name of the workflow.
package/v1/declaration.js CHANGED
@@ -111,7 +111,7 @@ class BaseWorkflowDeclaration {
111
111
  if (!this.client) {
112
112
  throw UNBOUND_ERR;
113
113
  }
114
- const scheduled = this.client._v0.schedule.create(this.definition.name, Object.assign({ triggerAt: enqueueAt, input: input }, options));
114
+ const scheduled = this.client.scheduled.create(this.definition.name, Object.assign({ triggerAt: enqueueAt, input: input }, options));
115
115
  return scheduled;
116
116
  });
117
117
  }
@@ -144,7 +144,7 @@ class BaseWorkflowDeclaration {
144
144
  if (!this.client) {
145
145
  throw UNBOUND_ERR;
146
146
  }
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 }));
147
+ const cronDef = this.client.crons.create(this.definition.name, Object.assign(Object.assign({ expression, input: input }, options), { additionalMetadata: options === null || options === void 0 ? void 0 : options.additionalMetadata, name }));
148
148
  return cronDef;
149
149
  });
150
150
  }
@@ -204,7 +204,9 @@ class BaseWorkflowDeclaration {
204
204
  // }
205
205
  // return this.client.workflows.unpause(this);
206
206
  // }
207
- // @deprecated use definition.name instead
207
+ /**
208
+ * @deprecated use definition.name instead
209
+ */
208
210
  get id() {
209
211
  return this.definition.name;
210
212
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const hatchet_client_1 = require("../hatchet-client");
4
+ const workflow_1 = require("./workflow");
5
+ // > Create a filter
6
+ hatchet_client_1.hatchet.filters.create({
7
+ workflowId: workflow_1.lower.id,
8
+ expression: 'input.ShouldSkip == false',
9
+ scope: 'foobarbaz',
10
+ payload: {
11
+ main_character: 'Anna',
12
+ supporting_character: 'Stiva',
13
+ location: 'Moscow',
14
+ },
15
+ });
16
+ // !!
17
+ // > Skip a run
18
+ hatchet_client_1.hatchet.events.push(workflow_1.SIMPLE_EVENT, {
19
+ Message: 'hello',
20
+ ShouldSkip: true,
21
+ }, {
22
+ scope: 'foobarbaz',
23
+ });
24
+ // !!
25
+ // > Trigger a run
26
+ hatchet_client_1.hatchet.events.push(workflow_1.SIMPLE_EVENT, {
27
+ Message: 'hello',
28
+ ShouldSkip: false,
29
+ }, {
30
+ scope: 'foobarbaz',
31
+ });
32
+ // !!
@@ -27,7 +27,7 @@ function main() {
27
27
  // !!
28
28
  // > List
29
29
  const crons = yield hatchet_client_1.hatchet.crons.list({
30
- workflowId: workflow_1.simple.id,
30
+ workflow: workflow_1.simple,
31
31
  });
32
32
  // !!
33
33
  // eslint-disable-next-line no-console
@@ -26,11 +26,11 @@ function main() {
26
26
  console.log(scheduledRunId);
27
27
  // !!
28
28
  // > Delete a Scheduled Run
29
- yield hatchet_client_1.hatchet.schedules.delete(scheduled);
29
+ yield hatchet_client_1.hatchet.scheduled.delete(scheduled);
30
30
  // !!
31
31
  // > List Scheduled Runs
32
- const scheduledRuns = yield hatchet_client_1.hatchet.schedules.list({
33
- workflowId: workflow_1.simple.id,
32
+ const scheduledRuns = yield hatchet_client_1.hatchet.scheduled.list({
33
+ workflow: workflow_1.simple,
34
34
  });
35
35
  console.log(scheduledRuns);
36
36
  // !!
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const HATCHET_VERSION = "1.6.1";
1
+ export declare const HATCHET_VERSION = "1.6.3";
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.6.1';
4
+ exports.HATCHET_VERSION = '1.6.3';