@hatchet-dev/typescript-sdk 0.1.22 → 0.1.23

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.
@@ -14,6 +14,7 @@ export interface Action {
14
14
  actionPayload: string;
15
15
  workflowRunId: string;
16
16
  getGroupKeyRunId: string;
17
+ stepName: string;
17
18
  }
18
19
  export declare class ActionListener {
19
20
  config: ClientConfig;
@@ -1,5 +1,5 @@
1
1
  import { Channel, ClientFactory } from 'nice-grpc';
2
- import { DispatcherClient as PbDispatcherClient, StepActionEvent, GroupKeyActionEvent } from '../../protoc/dispatcher';
2
+ import { DispatcherClient as PbDispatcherClient, StepActionEvent, GroupKeyActionEvent, OverridesData, DeepPartial } from '../../protoc/dispatcher';
3
3
  import { ClientConfig } from '../hatchet-client/client-config';
4
4
  import { Logger } from '../../util/logger';
5
5
  import { ActionListener } from './action-listener';
@@ -17,5 +17,6 @@ export declare class DispatcherClient {
17
17
  getActionListener(options: GetActionListenerOptions): Promise<ActionListener>;
18
18
  sendStepActionEvent(in_: StepActionEvent): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
19
19
  sendGroupKeyActionEvent(in_: GroupKeyActionEvent): Promise<import("../../protoc/dispatcher").ActionEventResponse>;
20
+ putOverridesData(in_: DeepPartial<OverridesData>): Promise<import("../../protoc/dispatcher").OverridesDataResponse>;
20
21
  }
21
22
  export {};
@@ -51,5 +51,15 @@ class DispatcherClient {
51
51
  }
52
52
  });
53
53
  }
54
+ putOverridesData(in_) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ try {
57
+ return (0, retrier_1.retrier)(() => __awaiter(this, void 0, void 0, function* () { return this.client.putOverridesData(in_); }), this.logger);
58
+ }
59
+ catch (e) {
60
+ throw new hatchet_error_1.default(e.message);
61
+ }
62
+ });
63
+ }
54
64
  }
55
65
  exports.DispatcherClient = DispatcherClient;
@@ -100,7 +100,7 @@ class Worker {
100
100
  handleStartStepRun(action) {
101
101
  const { actionId } = action;
102
102
  try {
103
- const context = new step_1.Context(action);
103
+ const context = new step_1.Context(action, this.client.dispatcher);
104
104
  this.contexts[action.stepRunId] = context;
105
105
  const step = this.action_registry[actionId];
106
106
  if (!step) {
@@ -149,7 +149,7 @@ class Worker {
149
149
  handleStartGroupKeyRun(action) {
150
150
  const { actionId } = action;
151
151
  try {
152
- const context = new step_1.Context(action);
152
+ const context = new step_1.Context(action, this.client.dispatcher);
153
153
  const key = action.getGroupKeyRunId;
154
154
  this.contexts[key] = context;
155
155
  this.logger.debug(`Starting group key run ${key}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatchet-dev/typescript-sdk",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Background task orchestration & visibility for developers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "event:concurrency": "npm run exec -- ./examples/concurrency/cancel-in-progress/concurrency-event.ts",
36
36
  "worker:concurrency:rr": "npm run exec -- ./examples/concurrency/group-round-robin/concurrency-worker.ts",
37
37
  "event:concurrency:rr": "npm run exec -- ./examples/concurrency/group-round-robin/concurrency-event.ts",
38
+ "worker:playground": "npm run exec -- ./examples/playground.ts",
38
39
  "worker:retries": "npm run exec -- ./examples/retries-worker.ts",
39
40
  "worker:multi-workflow": "npm run exec -- ./examples/multi-workflow.ts",
40
41
  "api": "npm run exec -- ./examples/api.ts",
@@ -87,6 +87,8 @@ export interface AssignedAction {
87
87
  actionType: ActionType;
88
88
  /** the action payload */
89
89
  actionPayload: string;
90
+ /** the step name */
91
+ stepName: string;
90
92
  }
91
93
  export interface WorkerListenRequest {
92
94
  /** the id of the worker */
@@ -442,6 +442,7 @@ function createBaseAssignedAction() {
442
442
  actionId: "",
443
443
  actionType: 0,
444
444
  actionPayload: "",
445
+ stepName: "",
445
446
  };
446
447
  }
447
448
  exports.AssignedAction = {
@@ -479,6 +480,9 @@ exports.AssignedAction = {
479
480
  if (message.actionPayload !== "") {
480
481
  writer.uint32(90).string(message.actionPayload);
481
482
  }
483
+ if (message.stepName !== "") {
484
+ writer.uint32(98).string(message.stepName);
485
+ }
482
486
  return writer;
483
487
  },
484
488
  decode(input, length) {
@@ -554,6 +558,12 @@ exports.AssignedAction = {
554
558
  }
555
559
  message.actionPayload = reader.string();
556
560
  continue;
561
+ case 12:
562
+ if (tag !== 98) {
563
+ break;
564
+ }
565
+ message.stepName = reader.string();
566
+ continue;
557
567
  }
558
568
  if ((tag & 7) === 4 || tag === 0) {
559
569
  break;
@@ -575,6 +585,7 @@ exports.AssignedAction = {
575
585
  actionId: isSet(object.actionId) ? globalThis.String(object.actionId) : "",
576
586
  actionType: isSet(object.actionType) ? actionTypeFromJSON(object.actionType) : 0,
577
587
  actionPayload: isSet(object.actionPayload) ? globalThis.String(object.actionPayload) : "",
588
+ stepName: isSet(object.stepName) ? globalThis.String(object.stepName) : "",
578
589
  };
579
590
  },
580
591
  toJSON(message) {
@@ -612,13 +623,16 @@ exports.AssignedAction = {
612
623
  if (message.actionPayload !== "") {
613
624
  obj.actionPayload = message.actionPayload;
614
625
  }
626
+ if (message.stepName !== "") {
627
+ obj.stepName = message.stepName;
628
+ }
615
629
  return obj;
616
630
  },
617
631
  create(base) {
618
632
  return exports.AssignedAction.fromPartial(base !== null && base !== void 0 ? base : {});
619
633
  },
620
634
  fromPartial(object) {
621
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
635
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
622
636
  const message = createBaseAssignedAction();
623
637
  message.tenantId = (_a = object.tenantId) !== null && _a !== void 0 ? _a : "";
624
638
  message.workflowRunId = (_b = object.workflowRunId) !== null && _b !== void 0 ? _b : "";
@@ -631,6 +645,7 @@ exports.AssignedAction = {
631
645
  message.actionId = (_j = object.actionId) !== null && _j !== void 0 ? _j : "";
632
646
  message.actionType = (_k = object.actionType) !== null && _k !== void 0 ? _k : 0;
633
647
  message.actionPayload = (_l = object.actionPayload) !== null && _l !== void 0 ? _l : "";
648
+ message.stepName = (_m = object.stepName) !== null && _m !== void 0 ? _m : "";
634
649
  return message;
635
650
  },
636
651
  };
package/step.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as z from 'zod';
2
2
  import { Action } from './clients/dispatcher/action-listener';
3
+ import { DispatcherClient } from './clients/dispatcher/dispatcher-client';
3
4
  export declare const CreateStepSchema: z.ZodObject<{
4
5
  name: z.ZodString;
5
6
  parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -16,7 +17,7 @@ export declare const CreateStepSchema: z.ZodObject<{
16
17
  timeout?: string | undefined;
17
18
  retries?: number | undefined;
18
19
  }>;
19
- type JSONPrimitive = string | number | boolean | null;
20
+ type JSONPrimitive = string | number | boolean | null | Array<JSONPrimitive>;
20
21
  export type NextStep = {
21
22
  [key: string]: NextStep | JSONPrimitive;
22
23
  };
@@ -30,11 +31,17 @@ export declare class Context<T, K> {
30
31
  data: ContextData<T, K>;
31
32
  input: T;
32
33
  controller: AbortController;
33
- constructor(action: Action);
34
+ action: Action;
35
+ client: DispatcherClient;
36
+ overridesData: Record<string, any>;
37
+ constructor(action: Action, client: DispatcherClient);
34
38
  stepOutput(step: string): NextStep;
35
39
  triggeredByEvent(): boolean;
36
40
  workflowInput(): T;
37
41
  userData(): K;
42
+ stepName(): string;
43
+ workflowRunId(): string;
44
+ playground(name: string, defaultValue?: string): string;
38
45
  }
39
46
  export type StepRunFunction<T, K> = (ctx: Context<T, K>) => Promise<NextStep> | NextStep | void;
40
47
  export interface CreateStep<T, K> extends z.infer<typeof CreateStepSchema> {
package/step.js CHANGED
@@ -37,11 +37,14 @@ exports.CreateStepSchema = z.object({
37
37
  retries: z.number().optional(),
38
38
  });
39
39
  class Context {
40
- constructor(action) {
40
+ constructor(action, client) {
41
41
  this.controller = new AbortController();
42
+ this.overridesData = {};
42
43
  try {
43
44
  const data = JSON.parse(JSON.parse(action.actionPayload));
44
45
  this.data = data;
46
+ this.action = action;
47
+ this.client = client;
45
48
  // if this is a getGroupKeyRunId, the data is the workflow input
46
49
  if (action.getGroupKeyRunId !== '') {
47
50
  this.input = data;
@@ -49,6 +52,7 @@ class Context {
49
52
  else {
50
53
  this.input = data.input;
51
54
  }
55
+ this.overridesData = data.overrides || {};
52
56
  }
53
57
  catch (e) {
54
58
  throw new hatchet_error_1.default(`Could not parse payload: ${e.message}`);
@@ -74,5 +78,22 @@ class Context {
74
78
  var _a;
75
79
  return (_a = this.data) === null || _a === void 0 ? void 0 : _a.user_data;
76
80
  }
81
+ stepName() {
82
+ return this.action.stepName;
83
+ }
84
+ workflowRunId() {
85
+ return this.action.workflowRunId;
86
+ }
87
+ playground(name, defaultValue = '') {
88
+ if (name in this.overridesData) {
89
+ return this.overridesData[name];
90
+ }
91
+ this.client.putOverridesData({
92
+ stepRunId: this.action.stepRunId,
93
+ path: name,
94
+ value: JSON.stringify(defaultValue),
95
+ });
96
+ return defaultValue;
97
+ }
77
98
  }
78
99
  exports.Context = Context;