@hatchet-dev/typescript-sdk 1.0.0-alpha1 → 1.0.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.
- package/clients/admin/admin-client.d.ts +15 -20
- package/clients/admin/admin-client.js +21 -17
- package/clients/hatchet-client/hatchet-client.d.ts +5 -4
- package/clients/hatchet-client/hatchet-client.js +6 -4
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +25 -0
- package/clients/listeners/durable-listener/durable-listener-client.js +30 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.d.ts +43 -0
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +241 -0
- package/clients/{listener/listener-client.d.ts → listeners/run-listener/child-listener-client.d.ts} +8 -8
- package/clients/{listener/listener-client.js → listeners/run-listener/child-listener-client.js} +8 -19
- package/clients/{listener/child-listener-client.d.ts → listeners/run-listener/pooled-child-listener-client.d.ts} +5 -5
- package/clients/{listener/child-listener-client.js → listeners/run-listener/pooled-child-listener-client.js} +5 -5
- package/clients/rest/generated/Api.d.ts +49 -2
- package/clients/rest/generated/Api.js +30 -0
- package/clients/rest/generated/data-contracts.d.ts +88 -82
- package/clients/rest/generated/data-contracts.js +8 -1
- package/clients/worker/worker.d.ts +5 -1
- package/clients/worker/worker.js +173 -2
- package/examples/affinity-workers.js +5 -1
- package/examples/api.js +1 -1
- package/examples/bulk-fanout-worker.js +1 -1
- package/examples/byo-logger.js +4 -0
- package/examples/concurrency/cancel-in-progress/concurrency-event.js +2 -2
- package/examples/concurrency/group-round-robin/concurrency-event.js +1 -1
- package/examples/crons/programatic-crons.js +4 -4
- package/examples/dag-worker.js +0 -1
- package/examples/example-event.js +2 -2
- package/examples/logger.js +2 -0
- package/examples/on-failure.js +1 -1
- package/examples/rate-limit/events.js +3 -3
- package/examples/scheduled-runs/programatic-schedules.js +4 -4
- package/examples/sticky-worker-with-check.js +2 -2
- package/examples/sticky-worker.js +5 -0
- package/index.d.ts +1 -3
- package/index.js +1 -3
- package/package.json +2 -2
- package/protoc/dispatcher/dispatcher.d.ts +2 -0
- package/protoc/dispatcher/dispatcher.js +1 -1
- package/protoc/events/events.js +1 -1
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/v1/dispatcher.d.ts +77 -0
- package/protoc/v1/dispatcher.js +341 -0
- package/protoc/v1/shared/condition.d.ts +59 -0
- package/protoc/v1/shared/condition.js +549 -0
- package/protoc/v1/workflows.d.ts +263 -0
- package/protoc/v1/workflows.js +1823 -0
- package/protoc/workflows/workflows.js +1 -1
- package/step.d.ts +173 -47
- package/step.js +208 -64
- package/util/sleep.d.ts +7 -0
- package/util/sleep.js +7 -0
- package/util/workflow-run-ref.d.ts +8 -2
- package/util/workflow-run-ref.js +13 -0
- package/v1/client/client.d.ts +125 -7
- package/v1/client/client.interface.d.ts +9 -1
- package/v1/client/client.js +148 -17
- package/v1/client/duration.d.ts +7 -0
- package/v1/client/duration.js +2 -0
- package/v1/client/features/index.d.ts +5 -0
- package/v1/client/features/index.js +21 -0
- package/v1/client/features/metrics.d.ts +14 -0
- package/v1/client/features/metrics.js +45 -0
- package/v1/client/features/ratelimits.d.ts +20 -0
- package/v1/client/features/ratelimits.js +40 -0
- package/v1/client/features/runs.d.ts +15 -0
- package/v1/client/features/runs.js +60 -0
- package/v1/client/features/workers.d.ts +14 -0
- package/v1/client/features/workers.js +56 -0
- package/v1/client/features/workflows.d.ts +17 -0
- package/v1/client/features/workflows.js +93 -0
- package/v1/client/worker.d.ts +25 -15
- package/v1/client/worker.js +76 -47
- package/v1/conditions/base.d.ts +18 -0
- package/v1/conditions/base.js +18 -0
- package/v1/conditions/index.d.ts +31 -0
- package/v1/conditions/index.js +91 -0
- package/v1/conditions/parent-condition.d.ts +40 -0
- package/v1/conditions/parent-condition.js +36 -0
- package/v1/conditions/sleep-condition.d.ts +47 -0
- package/v1/conditions/sleep-condition.js +38 -0
- package/v1/conditions/transformer.d.ts +5 -0
- package/v1/conditions/transformer.js +52 -0
- package/v1/conditions/user-event-condition.d.ts +50 -0
- package/v1/conditions/user-event-condition.js +39 -0
- package/v1/declaration.d.ts +309 -0
- package/v1/declaration.js +296 -0
- package/v1/examples/child_workflows/worker.js +2 -2
- package/v1/examples/child_workflows/workflow.d.ts +2 -2
- package/v1/examples/child_workflows/workflow.js +5 -3
- package/v1/examples/concurrency-rr/load.js +2 -2
- package/v1/examples/concurrency-rr/worker.js +2 -2
- package/v1/examples/concurrency-rr/workflow.d.ts +1 -1
- package/v1/examples/concurrency-rr/workflow.js +2 -3
- package/v1/examples/dag/worker.js +2 -2
- package/v1/examples/dag/workflow.d.ts +1 -1
- package/v1/examples/dag/workflow.js +3 -3
- package/v1/examples/dag_match_condition/event.js +28 -0
- package/v1/examples/dag_match_condition/run.d.ts +1 -0
- package/v1/examples/dag_match_condition/run.js +25 -0
- package/v1/examples/dag_match_condition/worker.d.ts +1 -0
- package/{examples/playground.js → v1/examples/dag_match_condition/worker.js} +7 -22
- package/v1/examples/dag_match_condition/workflow.d.ts +11 -0
- package/v1/examples/dag_match_condition/workflow.js +41 -0
- package/v1/examples/deep/worker.js +2 -2
- package/v1/examples/deep/workflow.d.ts +6 -6
- package/v1/examples/deep/workflow.js +7 -7
- package/v1/examples/durable-sleep/event.d.ts +1 -0
- package/v1/examples/durable-sleep/event.js +28 -0
- package/v1/examples/durable-sleep/run.d.ts +1 -0
- package/v1/examples/durable-sleep/run.js +30 -0
- package/v1/examples/durable-sleep/worker.d.ts +1 -0
- package/v1/examples/durable-sleep/worker.js +24 -0
- package/v1/examples/durable-sleep/workflow.d.ts +1 -0
- package/v1/examples/durable-sleep/workflow.js +37 -0
- package/v1/examples/inferred-typing/run.d.ts +1 -0
- package/v1/examples/inferred-typing/run.js +41 -0
- package/v1/examples/inferred-typing/worker.d.ts +1 -0
- package/v1/examples/inferred-typing/worker.js +24 -0
- package/v1/examples/inferred-typing/workflow.d.ts +15 -0
- package/v1/examples/inferred-typing/workflow.js +44 -0
- package/v1/examples/landing_page/durable-excution.d.ts +3 -0
- package/v1/examples/landing_page/durable-excution.js +40 -0
- package/v1/examples/landing_page/event-signaling.d.ts +6 -0
- package/v1/examples/landing_page/event-signaling.js +16 -0
- package/v1/examples/landing_page/flow-control.d.ts +6 -0
- package/v1/examples/landing_page/flow-control.js +26 -0
- package/v1/examples/landing_page/queues.d.ts +3 -0
- package/v1/examples/landing_page/queues.js +33 -0
- package/v1/examples/landing_page/scheduling.d.ts +1 -0
- package/v1/examples/landing_page/scheduling.js +12 -0
- package/v1/examples/landing_page/task-routing.d.ts +6 -0
- package/v1/examples/landing_page/task-routing.js +25 -0
- package/v1/examples/legacy/run.js +2 -2
- package/v1/examples/legacy/worker.js +2 -2
- package/v1/examples/on_cron/worker.d.ts +1 -0
- package/v1/examples/on_cron/worker.js +24 -0
- package/v1/examples/on_cron/workflow.d.ts +10 -0
- package/v1/examples/on_cron/workflow.js +21 -0
- package/v1/examples/on_event/event.js +3 -2
- package/v1/examples/on_event/worker.js +2 -2
- package/v1/examples/on_event/workflow.d.ts +4 -4
- package/v1/examples/on_event/workflow.js +6 -3
- package/v1/examples/on_event copy/event.d.ts +1 -0
- package/v1/examples/on_event copy/event.js +26 -0
- package/v1/examples/on_event copy/worker.d.ts +1 -0
- package/v1/examples/on_event copy/worker.js +24 -0
- package/v1/examples/on_event copy/workflow.d.ts +16 -0
- package/v1/examples/on_event copy/workflow.js +35 -0
- package/v1/examples/on_failure/worker.js +2 -2
- package/v1/examples/on_failure/workflow.d.ts +1 -1
- package/v1/examples/on_failure/workflow.js +18 -8
- package/v1/examples/on_success/run.d.ts +1 -0
- package/v1/examples/on_success/run.js +31 -0
- package/v1/examples/on_success/worker.d.ts +1 -0
- package/v1/examples/on_success/worker.js +24 -0
- package/v1/examples/on_success/workflow.d.ts +4 -0
- package/v1/examples/on_success/workflow.js +59 -0
- package/v1/examples/retries/run.d.ts +1 -0
- package/v1/examples/retries/run.js +29 -0
- package/v1/examples/retries/worker.d.ts +1 -0
- package/v1/examples/retries/worker.js +24 -0
- package/v1/examples/retries/workflow.d.ts +5 -0
- package/v1/examples/retries/workflow.js +53 -0
- package/v1/examples/simple/client-run.d.ts +1 -0
- package/v1/examples/simple/client-run.js +16 -0
- package/v1/examples/simple/cron.js +6 -2
- package/v1/examples/simple/delay.js +2 -2
- package/v1/examples/simple/enqueue.d.ts +1 -0
- package/v1/examples/simple/enqueue.js +43 -0
- package/v1/examples/simple/run.js +8 -3
- package/v1/examples/simple/schedule.js +11 -5
- package/v1/examples/simple/stub-workflow.d.ts +9 -0
- package/v1/examples/simple/stub-workflow.js +17 -0
- package/v1/examples/simple/worker.js +7 -2
- package/v1/examples/simple/workflow.d.ts +4 -3
- package/v1/examples/simple/workflow.js +5 -5
- package/v1/examples/sticky/run.d.ts +1 -0
- package/v1/examples/sticky/run.js +29 -0
- package/v1/examples/sticky/worker.d.ts +1 -0
- package/v1/examples/sticky/worker.js +24 -0
- package/v1/examples/sticky/workflow.d.ts +7 -0
- package/v1/examples/sticky/workflow.js +32 -0
- package/v1/examples/with_timeouts/workflow.d.ts +9 -0
- package/v1/examples/with_timeouts/workflow.js +62 -0
- package/v1/index.d.ts +5 -0
- package/v1/index.js +20 -0
- package/v1/task.d.ts +144 -14
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/v1/workflow.d.ts +0 -158
- package/v1/workflow.js +0 -145
- /package/{examples/playground.d.ts → v1/examples/dag_match_condition/event.d.ts} +0 -0
- /package/v1/examples/{client.d.ts → hatchet-client.d.ts} +0 -0
- /package/v1/examples/{client.js → hatchet-client.js} +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
/* eslint-disable no-shadow */
|
|
4
|
+
/* eslint-disable max-classes-per-file */
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OrCondition = exports.UserEventCondition = exports.SleepCondition = void 0;
|
|
7
|
+
exports.Render = Render;
|
|
8
|
+
exports.Or = Or;
|
|
9
|
+
exports.generateGroupId = generateGroupId;
|
|
10
|
+
const base_1 = require("./base");
|
|
11
|
+
const parent_condition_1 = require("./parent-condition");
|
|
12
|
+
const sleep_condition_1 = require("./sleep-condition");
|
|
13
|
+
Object.defineProperty(exports, "SleepCondition", { enumerable: true, get: function () { return sleep_condition_1.SleepCondition; } });
|
|
14
|
+
const user_event_condition_1 = require("./user-event-condition");
|
|
15
|
+
Object.defineProperty(exports, "UserEventCondition", { enumerable: true, get: function () { return user_event_condition_1.UserEventCondition; } });
|
|
16
|
+
class OrCondition {
|
|
17
|
+
constructor(conditions) {
|
|
18
|
+
this.conditions = conditions;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.OrCondition = OrCondition;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a condition that waits for all provided conditions to be met (AND logic)
|
|
24
|
+
* use Or() to create a condition that waits for any of the provided conditions to be met (OR logic)
|
|
25
|
+
* @param conditions - Conditions or OrConditions to be rendered
|
|
26
|
+
* @returns A flattened array of Conditions
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* const conditions = Render(
|
|
30
|
+
* Or({ sleepFor: 5 }, { eventKey: 'user:update' }),
|
|
31
|
+
* { eventKey: 'user:create' },
|
|
32
|
+
* Or({ eventKey: 'user:update' }, { eventKey: 'user:delete' })
|
|
33
|
+
* );
|
|
34
|
+
*/
|
|
35
|
+
function Render(action, conditions) {
|
|
36
|
+
if (!conditions)
|
|
37
|
+
return [];
|
|
38
|
+
if (!Array.isArray(conditions)) {
|
|
39
|
+
return Render(action, [conditions]);
|
|
40
|
+
}
|
|
41
|
+
const renderedConditions = conditions.reduce((acc, conditionOrObj) => {
|
|
42
|
+
if (conditionOrObj instanceof base_1.Condition) {
|
|
43
|
+
return [...acc, conditionOrObj];
|
|
44
|
+
}
|
|
45
|
+
if (conditionOrObj instanceof OrCondition) {
|
|
46
|
+
return [...acc, ...Render(action, conditionOrObj.conditions)];
|
|
47
|
+
}
|
|
48
|
+
// Handle object syntax
|
|
49
|
+
if ('sleepFor' in conditionOrObj) {
|
|
50
|
+
return [...acc, new sleep_condition_1.SleepCondition(conditionOrObj.sleepFor, undefined, action)];
|
|
51
|
+
}
|
|
52
|
+
if ('eventKey' in conditionOrObj) {
|
|
53
|
+
return [
|
|
54
|
+
...acc,
|
|
55
|
+
new user_event_condition_1.UserEventCondition(conditionOrObj.eventKey, conditionOrObj.expression || '', undefined, action),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
if ('parent' in conditionOrObj) {
|
|
59
|
+
return [
|
|
60
|
+
...acc,
|
|
61
|
+
new parent_condition_1.ParentCondition(conditionOrObj.parent, conditionOrObj.expression || '', undefined, action),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Unknown condition object: ${JSON.stringify(conditionOrObj)}`);
|
|
65
|
+
}, []);
|
|
66
|
+
// set the action for each condition
|
|
67
|
+
return renderedConditions.filter((condition) => {
|
|
68
|
+
if (condition instanceof base_1.Condition) {
|
|
69
|
+
condition.base.action = action;
|
|
70
|
+
}
|
|
71
|
+
return condition;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a condition group with OR logic
|
|
76
|
+
* Flattens nested Or conditions to ensure proper grouping
|
|
77
|
+
*/
|
|
78
|
+
function Or(...conditionsOrObjs) {
|
|
79
|
+
// must be Condition[] because OrCondition is not a Condition
|
|
80
|
+
const conditions = Render(undefined, conditionsOrObjs);
|
|
81
|
+
const orGroupId = generateGroupId();
|
|
82
|
+
conditions.forEach((condition) => {
|
|
83
|
+
if (condition instanceof base_1.Condition) {
|
|
84
|
+
condition.base.orGroupId = orGroupId;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return new OrCondition(conditions);
|
|
88
|
+
}
|
|
89
|
+
function generateGroupId() {
|
|
90
|
+
return crypto.randomUUID ? crypto.randomUUID() : `or-${Date.now()}-${Math.random()}`;
|
|
91
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Condition, Action } from './base';
|
|
2
|
+
import { CreateWorkflowTaskOpts } from '../task';
|
|
3
|
+
export interface Parent {
|
|
4
|
+
/**
|
|
5
|
+
* The parent workflow task this condition is associated with.
|
|
6
|
+
* This establishes a relationship between this condition and a specific workflow task.
|
|
7
|
+
*/
|
|
8
|
+
parent: CreateWorkflowTaskOpts<any, any>;
|
|
9
|
+
/**
|
|
10
|
+
* Optional CEL expression to evaluate against the parent task's data.
|
|
11
|
+
* When provided, the condition will only trigger if this expression evaluates to true.
|
|
12
|
+
* @example "input.status == 'completed'", "input.result > 0"
|
|
13
|
+
*/
|
|
14
|
+
expression?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Represents a condition that is triggered based on a parent workflow task.
|
|
18
|
+
* This condition monitors the specified parent task and evaluates
|
|
19
|
+
* any provided expression against the task's data.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Create a condition that triggers when a parent task completes successfully
|
|
23
|
+
* const parentCondition = new ParentCondition(
|
|
24
|
+
* parentTaskOpts,
|
|
25
|
+
* "input.status == 'success'",
|
|
26
|
+
* () => console.log("Parent task completed successfully!")
|
|
27
|
+
* );
|
|
28
|
+
*/
|
|
29
|
+
export declare class ParentCondition extends Condition {
|
|
30
|
+
/** The parent workflow task this condition is associated with */
|
|
31
|
+
parent: CreateWorkflowTaskOpts<any, any>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new condition that is triggered based on a parent workflow task.
|
|
34
|
+
*
|
|
35
|
+
* @param parent The parent workflow task this condition is associated with
|
|
36
|
+
* @param expression Optional CEL expression to evaluate against the parent task's data
|
|
37
|
+
* @param action Optional action to execute when the condition is met
|
|
38
|
+
*/
|
|
39
|
+
constructor(parent: CreateWorkflowTaskOpts<any, any>, expression?: string, readableDataKey?: string, action?: Action);
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParentCondition = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a condition that is triggered based on a parent workflow task.
|
|
7
|
+
* This condition monitors the specified parent task and evaluates
|
|
8
|
+
* any provided expression against the task's data.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Create a condition that triggers when a parent task completes successfully
|
|
12
|
+
* const parentCondition = new ParentCondition(
|
|
13
|
+
* parentTaskOpts,
|
|
14
|
+
* "input.status == 'success'",
|
|
15
|
+
* () => console.log("Parent task completed successfully!")
|
|
16
|
+
* );
|
|
17
|
+
*/
|
|
18
|
+
class ParentCondition extends base_1.Condition {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new condition that is triggered based on a parent workflow task.
|
|
21
|
+
*
|
|
22
|
+
* @param parent The parent workflow task this condition is associated with
|
|
23
|
+
* @param expression Optional CEL expression to evaluate against the parent task's data
|
|
24
|
+
* @param action Optional action to execute when the condition is met
|
|
25
|
+
*/
|
|
26
|
+
constructor(parent, expression, readableDataKey, action) {
|
|
27
|
+
super({
|
|
28
|
+
readableDataKey: readableDataKey || `parent-${parent.name || Date.now().toString()}`,
|
|
29
|
+
action,
|
|
30
|
+
orGroupId: '',
|
|
31
|
+
expression: expression || '',
|
|
32
|
+
});
|
|
33
|
+
this.parent = parent;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.ParentCondition = ParentCondition;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Duration } from '../client/duration';
|
|
2
|
+
import { Condition, Action } from './base';
|
|
3
|
+
export interface Sleep {
|
|
4
|
+
/**
|
|
5
|
+
* Amount of time to sleep for.
|
|
6
|
+
* Specifies how long this condition should wait before proceeding.
|
|
7
|
+
* Uses Go duration string format.
|
|
8
|
+
*
|
|
9
|
+
* @example "10s", "1m", "1m5s", "24h"
|
|
10
|
+
*/
|
|
11
|
+
sleepFor: Duration;
|
|
12
|
+
/**
|
|
13
|
+
* Optional unique identifier for the sleep condition in the readable stream.
|
|
14
|
+
* When multiple conditions have the same sleep duration,
|
|
15
|
+
* using a custom readableDataKey prevents duplicate data processing
|
|
16
|
+
* by differentiating between the conditions in the data store.
|
|
17
|
+
* If not specified, a default identifier based on the sleep duration will be used.
|
|
18
|
+
*/
|
|
19
|
+
readableDataKey?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Represents a condition that waits for a specified duration before proceeding.
|
|
23
|
+
* This condition is useful for implementing time delays in workflows.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Create a condition that waits for 5 minutes
|
|
27
|
+
* const waitCondition = new SleepCondition(
|
|
28
|
+
* "5m",
|
|
29
|
+
* "reminder_delay",
|
|
30
|
+
* () => console.log("Wait period completed!")
|
|
31
|
+
* );
|
|
32
|
+
*/
|
|
33
|
+
export declare class SleepCondition extends Condition {
|
|
34
|
+
/** The duration to sleep for in Go duration string format */
|
|
35
|
+
sleepFor: Duration;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new sleep condition that waits for the specified duration.
|
|
38
|
+
*
|
|
39
|
+
* @param sleepFor Duration to wait in Go duration string format (e.g., "30s", "5m")
|
|
40
|
+
* @param readableDataKey Optional unique identifier for the condition data.
|
|
41
|
+
* When multiple sleep conditions have the same duration, using a custom
|
|
42
|
+
* readableDataKey prevents duplicate data by differentiating between them.
|
|
43
|
+
* If not provided, defaults to `sleep-${sleepFor}`.
|
|
44
|
+
* @param action Optional action to execute when the sleep duration completes
|
|
45
|
+
*/
|
|
46
|
+
constructor(sleepFor: Duration, readableDataKey?: string, action?: Action);
|
|
47
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SleepCondition = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a condition that waits for a specified duration before proceeding.
|
|
7
|
+
* This condition is useful for implementing time delays in workflows.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Create a condition that waits for 5 minutes
|
|
11
|
+
* const waitCondition = new SleepCondition(
|
|
12
|
+
* "5m",
|
|
13
|
+
* "reminder_delay",
|
|
14
|
+
* () => console.log("Wait period completed!")
|
|
15
|
+
* );
|
|
16
|
+
*/
|
|
17
|
+
class SleepCondition extends base_1.Condition {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new sleep condition that waits for the specified duration.
|
|
20
|
+
*
|
|
21
|
+
* @param sleepFor Duration to wait in Go duration string format (e.g., "30s", "5m")
|
|
22
|
+
* @param readableDataKey Optional unique identifier for the condition data.
|
|
23
|
+
* When multiple sleep conditions have the same duration, using a custom
|
|
24
|
+
* readableDataKey prevents duplicate data by differentiating between them.
|
|
25
|
+
* If not provided, defaults to `sleep-${sleepFor}`.
|
|
26
|
+
* @param action Optional action to execute when the sleep duration completes
|
|
27
|
+
*/
|
|
28
|
+
constructor(sleepFor, readableDataKey, action) {
|
|
29
|
+
super({
|
|
30
|
+
readableDataKey: readableDataKey || `sleep-${sleepFor}`,
|
|
31
|
+
action,
|
|
32
|
+
orGroupId: '',
|
|
33
|
+
expression: '',
|
|
34
|
+
});
|
|
35
|
+
this.sleepFor = sleepFor;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.SleepCondition = SleepCondition;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TaskConditions } from '../../protoc/v1/shared/condition';
|
|
2
|
+
import { CreateWorkflowTaskOpts } from '../task';
|
|
3
|
+
import { Condition } from './base';
|
|
4
|
+
export declare function taskConditionsToPb(task: Omit<CreateWorkflowTaskOpts<any, any>, 'fn'>): TaskConditions;
|
|
5
|
+
export declare function conditionsToPb(conditions: Condition[]): TaskConditions;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taskConditionsToPb = taskConditionsToPb;
|
|
4
|
+
exports.conditionsToPb = conditionsToPb;
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
const parent_condition_1 = require("./parent-condition");
|
|
8
|
+
function taskConditionsToPb(task) {
|
|
9
|
+
const waitForConditions = (0, _1.Render)(base_1.Action.QUEUE, task.waitFor);
|
|
10
|
+
const cancelIfConditions = (0, _1.Render)(base_1.Action.CANCEL, task.cancelIf);
|
|
11
|
+
const skipIfConditions = (0, _1.Render)(base_1.Action.SKIP, task.skipIf);
|
|
12
|
+
const mergedConditions = [...waitForConditions, ...cancelIfConditions, ...skipIfConditions];
|
|
13
|
+
return conditionsToPb(mergedConditions);
|
|
14
|
+
}
|
|
15
|
+
function conditionsToPb(conditions) {
|
|
16
|
+
const parentOverrideConditions = [];
|
|
17
|
+
const sleepConditions = [];
|
|
18
|
+
const userEventConditions = [];
|
|
19
|
+
conditions.forEach((condition) => {
|
|
20
|
+
if (condition instanceof _1.SleepCondition) {
|
|
21
|
+
sleepConditions.push({
|
|
22
|
+
base: baseToPb(condition.base),
|
|
23
|
+
sleepFor: condition.sleepFor,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else if (condition instanceof _1.UserEventCondition) {
|
|
27
|
+
userEventConditions.push({
|
|
28
|
+
base: Object.assign(Object.assign({}, baseToPb(condition.base)), { expression: condition.expression || '' }),
|
|
29
|
+
userEventKey: condition.eventKey,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (condition instanceof parent_condition_1.ParentCondition) {
|
|
33
|
+
parentOverrideConditions.push({
|
|
34
|
+
base: baseToPb(condition.base),
|
|
35
|
+
parentReadableId: condition.parent.name,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
parentOverrideConditions,
|
|
41
|
+
sleepConditions,
|
|
42
|
+
userEventConditions,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function baseToPb(base) {
|
|
46
|
+
return {
|
|
47
|
+
readableDataKey: base.readableDataKey || '',
|
|
48
|
+
action: base.action,
|
|
49
|
+
orGroupId: base.orGroupId || (0, _1.generateGroupId)(),
|
|
50
|
+
expression: base.expression || '',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Condition, Action } from './base';
|
|
2
|
+
export interface UserEvent {
|
|
3
|
+
/**
|
|
4
|
+
* The unique key identifying the specific user event to monitor.
|
|
5
|
+
* This should match the event key that will be emitted from your application.
|
|
6
|
+
* @example "button:clicked", "page:viewed", "form:submitted"
|
|
7
|
+
*/
|
|
8
|
+
eventKey: string;
|
|
9
|
+
/**
|
|
10
|
+
* Optional CEL expression to evaluate against the event data.
|
|
11
|
+
* When provided, the condition will only trigger if this expression evaluates to true.
|
|
12
|
+
* @example "input.quantity > 5", "input.status == 'completed'"
|
|
13
|
+
*/
|
|
14
|
+
expression?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional unique identifier for the event data in the readable stream.
|
|
17
|
+
* When multiple conditions are listening to the same event type,
|
|
18
|
+
* using a custom readableDataKey prevents duplicate data processing
|
|
19
|
+
* by differentiating between the conditions in the data store.
|
|
20
|
+
* If not specified, the eventKey will be used as the default identifier.
|
|
21
|
+
*/
|
|
22
|
+
readableDataKey?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents a condition that is triggered based on a specific user event.
|
|
26
|
+
* This condition monitors for events with the specified key and evaluates
|
|
27
|
+
* any provided expression against the event data.
|
|
28
|
+
*
|
|
29
|
+
* @param eventKey The key identifying the specific user event to monitor
|
|
30
|
+
* @param expression The CEL expression to evaluate against the event data
|
|
31
|
+
* @param readableDataKey Optional parameter that provides a unique identifier for the data.
|
|
32
|
+
* When multiple conditions are listening to the same event, using a custom
|
|
33
|
+
* readableDataKey prevents duplicate data by differentiating between the conditions.
|
|
34
|
+
* If not provided, defaults to the eventKey.
|
|
35
|
+
* @param action Optional action to execute when the condition is met
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Create a condition that triggers when a "purchase" event occurs with amount > 100
|
|
39
|
+
* const purchaseCondition = new UserEventCondition(
|
|
40
|
+
* "purchase",
|
|
41
|
+
* "data.amount > 100",
|
|
42
|
+
* "high_value_purchase",
|
|
43
|
+
* () => console.log("High value purchase detected!")
|
|
44
|
+
* );
|
|
45
|
+
*/
|
|
46
|
+
export declare class UserEventCondition extends Condition {
|
|
47
|
+
eventKey: string;
|
|
48
|
+
expression: string;
|
|
49
|
+
constructor(eventKey: string, expression: string, readableDataKey?: string, action?: Action);
|
|
50
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserEventCondition = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a condition that is triggered based on a specific user event.
|
|
7
|
+
* This condition monitors for events with the specified key and evaluates
|
|
8
|
+
* any provided expression against the event data.
|
|
9
|
+
*
|
|
10
|
+
* @param eventKey The key identifying the specific user event to monitor
|
|
11
|
+
* @param expression The CEL expression to evaluate against the event data
|
|
12
|
+
* @param readableDataKey Optional parameter that provides a unique identifier for the data.
|
|
13
|
+
* When multiple conditions are listening to the same event, using a custom
|
|
14
|
+
* readableDataKey prevents duplicate data by differentiating between the conditions.
|
|
15
|
+
* If not provided, defaults to the eventKey.
|
|
16
|
+
* @param action Optional action to execute when the condition is met
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Create a condition that triggers when a "purchase" event occurs with amount > 100
|
|
20
|
+
* const purchaseCondition = new UserEventCondition(
|
|
21
|
+
* "purchase",
|
|
22
|
+
* "data.amount > 100",
|
|
23
|
+
* "high_value_purchase",
|
|
24
|
+
* () => console.log("High value purchase detected!")
|
|
25
|
+
* );
|
|
26
|
+
*/
|
|
27
|
+
class UserEventCondition extends base_1.Condition {
|
|
28
|
+
constructor(eventKey, expression, readableDataKey, action) {
|
|
29
|
+
super({
|
|
30
|
+
readableDataKey: readableDataKey || eventKey,
|
|
31
|
+
action,
|
|
32
|
+
orGroupId: '',
|
|
33
|
+
expression: '',
|
|
34
|
+
});
|
|
35
|
+
this.eventKey = eventKey;
|
|
36
|
+
this.expression = expression;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.UserEventCondition = UserEventCondition;
|