@hatchet-dev/typescript-sdk 1.16.0 → 1.17.1
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/README.md +14 -2
- package/clients/admin/admin-client.d.ts +2 -2
- package/clients/dispatcher/action-listener.d.ts +3 -6
- package/clients/dispatcher/action-listener.js +12 -17
- package/clients/listeners/durable-listener/durable-listener-client.d.ts +116 -15
- package/clients/listeners/durable-listener/durable-listener-client.js +770 -19
- package/clients/listeners/durable-listener/pooled-durable-listener-client.js +1 -14
- package/clients/listeners/run-listener/pooled-child-listener-client.js +1 -14
- package/clients/rest/generated/Api.d.ts +5 -1
- package/clients/rest/generated/data-contracts.d.ts +16 -2
- package/clients/rest/generated/data-contracts.js +7 -3
- package/legacy/examples/affinity-workers.js +2 -2
- package/legacy/legacy-client.js +1 -1
- package/legacy/step.d.ts +2 -2
- package/legacy/step.js +3 -2
- package/legacy/workflow.d.ts +25 -25
- package/package.json +1 -1
- package/protoc/dispatcher/dispatcher.d.ts +20 -0
- package/protoc/dispatcher/dispatcher.js +535 -100
- package/protoc/events/events.js +54 -14
- package/protoc/google/protobuf/timestamp.js +1 -1
- package/protoc/v1/dispatcher.d.ts +169 -0
- package/protoc/v1/dispatcher.js +2096 -8
- package/protoc/v1/shared/condition.js +37 -11
- package/protoc/v1/shared/trigger.d.ts +89 -0
- package/protoc/v1/shared/trigger.js +524 -0
- package/protoc/v1/workflows.d.ts +34 -34
- package/protoc/v1/workflows.js +452 -254
- package/protoc/workflows/workflows.d.ts +2 -75
- package/protoc/workflows/workflows.js +157 -529
- package/util/abort-error.d.ts +10 -0
- package/util/abort-error.js +15 -0
- package/util/errors/eviction-not-supported-error.d.ts +5 -0
- package/util/errors/eviction-not-supported-error.js +18 -0
- package/util/errors/non-determinism-error.d.ts +7 -0
- package/util/errors/non-determinism-error.js +21 -0
- package/util/errors/task-run-terminated-error.d.ts +6 -0
- package/util/errors/task-run-terminated-error.js +15 -0
- package/util/hatchet-promise/hatchet-promise.d.ts +2 -1
- package/util/hatchet-promise/hatchet-promise.js +10 -1
- package/util/sleep.d.ts +3 -2
- package/util/sleep.js +6 -4
- package/v1/client/admin.d.ts +2 -2
- package/v1/client/client.js +1 -1
- package/v1/client/duration.d.ts +11 -1
- package/v1/client/duration.js +44 -0
- package/v1/client/features/runs.d.ts +16 -3
- package/v1/client/features/runs.js +38 -3
- package/v1/client/worker/context.d.ts +101 -6
- package/v1/client/worker/context.js +247 -21
- package/v1/client/worker/deprecated/index.d.ts +1 -1
- package/v1/client/worker/deprecated/index.js +2 -1
- package/v1/client/worker/deprecated/legacy-worker.d.ts +5 -0
- package/v1/client/worker/deprecated/legacy-worker.js +32 -23
- package/v1/client/worker/deprecated/pre-eviction.d.ts +12 -0
- package/v1/client/worker/deprecated/pre-eviction.js +37 -0
- package/v1/client/worker/engine-version.d.ts +5 -0
- package/v1/client/worker/engine-version.js +14 -0
- package/v1/client/worker/eviction/eviction-cache.d.ts +33 -0
- package/v1/client/worker/eviction/eviction-cache.js +139 -0
- package/v1/client/worker/eviction/eviction-manager.d.ts +42 -0
- package/v1/client/worker/eviction/eviction-manager.js +132 -0
- package/v1/client/worker/eviction/eviction-policy.d.ts +19 -0
- package/v1/client/worker/eviction/eviction-policy.js +8 -0
- package/v1/client/worker/eviction/index.d.ts +3 -0
- package/v1/client/worker/eviction/index.js +11 -0
- package/v1/client/worker/worker-internal.d.ts +23 -4
- package/v1/client/worker/worker-internal.js +177 -138
- package/v1/client/worker/worker.d.ts +1 -0
- package/v1/client/worker/worker.js +34 -1
- package/v1/conditions/sleep-condition.js +2 -1
- package/v1/conditions/transformer.js +2 -1
- package/v1/declaration.d.ts +5 -3
- package/v1/declaration.js +8 -0
- package/v1/examples/__e2e__/harness.d.ts +5 -0
- package/v1/examples/__e2e__/harness.js +13 -0
- package/v1/examples/concurrency_workflow_level/workflow.d.ts +1 -1
- package/v1/examples/concurrency_workflow_level/workflow.js +1 -1
- package/v1/examples/durable/workflow.d.ts +57 -0
- package/v1/examples/durable/workflow.js +162 -7
- package/v1/examples/durable-event/workflow.js +2 -7
- package/v1/examples/durable_event/workflow.d.ts +1 -0
- package/v1/examples/durable_event/workflow.js +4 -9
- package/v1/examples/durable_eviction/capacity-worker.d.ts +1 -0
- package/v1/examples/durable_eviction/capacity-worker.js +31 -0
- package/v1/examples/durable_eviction/worker.d.ts +1 -0
- package/v1/examples/durable_eviction/worker.js +34 -0
- package/v1/examples/durable_eviction/workflow.d.ts +44 -0
- package/v1/examples/durable_eviction/workflow.js +129 -0
- package/v1/examples/e2e-worker.js +42 -19
- package/v1/index.d.ts +5 -0
- package/v1/index.js +10 -0
- package/v1/parent-run-context-vars.d.ts +6 -0
- package/v1/task.d.ts +10 -2
- package/v1/task.js +2 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/README.md
CHANGED
|
@@ -63,9 +63,21 @@ pnpm install
|
|
|
63
63
|
pnpm build
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
3. Run tests:
|
|
66
|
+
3. Run unit tests:
|
|
67
67
|
```bash
|
|
68
|
-
pnpm test
|
|
68
|
+
pnpm test:unit
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
4. Run e2e tests (requires a running Hatchet engine):
|
|
72
|
+
```bash
|
|
73
|
+
# Run all e2e tests
|
|
74
|
+
pnpm test:e2e
|
|
75
|
+
|
|
76
|
+
# Run a specific e2e test file
|
|
77
|
+
pnpm test:e2e durable.e2e.ts
|
|
78
|
+
|
|
79
|
+
# Run a specific test by name
|
|
80
|
+
pnpm test:e2e durable.e2e.ts -t "durable replay reset"
|
|
69
81
|
```
|
|
70
82
|
|
|
71
83
|
## Contributing
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
|
-
import { CreateWorkflowVersionOpts, RateLimitDuration,
|
|
2
|
+
import { CreateWorkflowVersionOpts, RateLimitDuration, WorkflowServiceClient } from '../../protoc/workflows';
|
|
3
3
|
import { ClientConfig } from '../hatchet-client/client-config';
|
|
4
4
|
import { Logger } from '../../util/logger';
|
|
5
5
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
6
6
|
import { AdminServiceClient, CreateWorkflowVersionRequest } from '../../protoc/v1/workflows';
|
|
7
|
-
import { Priority, RunsClient } from '../../v1';
|
|
7
|
+
import { Priority, RunsClient, WorkerLabelComparator } from '../../v1';
|
|
8
8
|
import { Api } from '../rest';
|
|
9
9
|
import { WebhookWorkerCreateRequest, WorkflowRunStatus, WorkflowRunStatusList } from '../rest/generated/data-contracts';
|
|
10
10
|
import { RunListenerClient } from '../listeners/run-listener/child-listener-client';
|
|
@@ -7,14 +7,11 @@ declare enum ListenStrategy {
|
|
|
7
7
|
LISTEN_STRATEGY_V1 = 1,
|
|
8
8
|
LISTEN_STRATEGY_V2 = 2
|
|
9
9
|
}
|
|
10
|
+
export type ActionKey = `${string}/${number}`;
|
|
10
11
|
export type Action = AssignedAction & {
|
|
11
|
-
|
|
12
|
-
stepRunId?: string;
|
|
13
|
-
/** @deprecated use taskId */
|
|
14
|
-
stepId?: string;
|
|
12
|
+
readonly key: ActionKey;
|
|
15
13
|
};
|
|
16
|
-
export
|
|
17
|
-
export declare function createActionKey(action: Action): ActionKey;
|
|
14
|
+
export declare function createAction(assignedAction: AssignedAction): Action;
|
|
18
15
|
export declare class ActionListener {
|
|
19
16
|
config: ClientConfig;
|
|
20
17
|
client: PbDispatcherClient;
|
|
@@ -66,8 +66,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
66
66
|
};
|
|
67
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
68
|
exports.ActionListener = void 0;
|
|
69
|
-
exports.
|
|
70
|
-
const dispatcher_1 = require("../../protoc/dispatcher");
|
|
69
|
+
exports.createAction = createAction;
|
|
71
70
|
const nice_grpc_1 = require("nice-grpc");
|
|
72
71
|
const grpc_error_1 = require("../../util/grpc-error");
|
|
73
72
|
const abort_controller_x_1 = require("abort-controller-x");
|
|
@@ -81,19 +80,16 @@ var ListenStrategy;
|
|
|
81
80
|
ListenStrategy[ListenStrategy["LISTEN_STRATEGY_V1"] = 1] = "LISTEN_STRATEGY_V1";
|
|
82
81
|
ListenStrategy[ListenStrategy["LISTEN_STRATEGY_V2"] = 2] = "LISTEN_STRATEGY_V2";
|
|
83
82
|
})(ListenStrategy || (ListenStrategy = {}));
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const exhaustivenessCheck = action.actionType;
|
|
95
|
-
throw new Error(`Unhandled action type: ${exhaustivenessCheck}`);
|
|
96
|
-
}
|
|
83
|
+
function createAction(assignedAction) {
|
|
84
|
+
const action = assignedAction;
|
|
85
|
+
Object.defineProperty(action, 'key', {
|
|
86
|
+
get() {
|
|
87
|
+
return `${this.taskRunExternalId}/${this.retryCount}`;
|
|
88
|
+
},
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
});
|
|
92
|
+
return action;
|
|
97
93
|
}
|
|
98
94
|
class ActionListener {
|
|
99
95
|
constructor(client, workerId, retryInterval = DEFAULT_ACTION_LISTENER_RETRY_INTERVAL, retryCount = DEFAULT_ACTION_LISTENER_RETRY_COUNT) {
|
|
@@ -117,8 +113,7 @@ class ActionListener {
|
|
|
117
113
|
_c = listenClient_1_1.value;
|
|
118
114
|
_d = false;
|
|
119
115
|
const assignedAction = _c;
|
|
120
|
-
|
|
121
|
-
yield yield __await(action);
|
|
116
|
+
yield yield __await(createAction(assignedAction));
|
|
122
117
|
}
|
|
123
118
|
}
|
|
124
119
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -1,31 +1,132 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
1
2
|
import { Channel, ClientFactory } from 'nice-grpc';
|
|
2
3
|
import { ClientConfig } from '../../hatchet-client/client-config';
|
|
3
4
|
import { Logger } from '../../../util/logger';
|
|
4
|
-
import { V1DispatcherClient } from '../../../protoc/v1/dispatcher';
|
|
5
|
-
import { SleepMatchCondition, UserEventMatchCondition } from '../../../protoc/v1/shared/condition';
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { V1DispatcherClient, DurableEvent, RegisterDurableEventResponse } from '../../../protoc/v1/dispatcher';
|
|
6
|
+
import { DurableEventListenerConditions, SleepMatchCondition, UserEventMatchCondition } from '../../../protoc/v1/shared/condition';
|
|
7
|
+
import { TriggerWorkflowRequest } from '../../../protoc/v1/shared/trigger';
|
|
8
|
+
export interface DurableTaskRunAckEntryResult {
|
|
9
|
+
nodeId: number;
|
|
10
|
+
branchId: number;
|
|
11
|
+
workflowRunExternalId: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DurableTaskEventRunAck {
|
|
14
|
+
ackType: 'run';
|
|
15
|
+
invocationCount: number;
|
|
16
|
+
durableTaskExternalId: string;
|
|
17
|
+
runEntries: DurableTaskRunAckEntryResult[];
|
|
18
|
+
}
|
|
19
|
+
export interface DurableTaskEventMemoAck {
|
|
20
|
+
ackType: 'memo';
|
|
21
|
+
invocationCount: number;
|
|
22
|
+
durableTaskExternalId: string;
|
|
23
|
+
branchId: number;
|
|
24
|
+
nodeId: number;
|
|
25
|
+
memoAlreadyExisted: boolean;
|
|
26
|
+
memoResultPayload?: Uint8Array;
|
|
27
|
+
}
|
|
28
|
+
export interface DurableTaskEventWaitForAck {
|
|
29
|
+
ackType: 'waitFor';
|
|
30
|
+
invocationCount: number;
|
|
31
|
+
durableTaskExternalId: string;
|
|
32
|
+
branchId: number;
|
|
33
|
+
nodeId: number;
|
|
34
|
+
}
|
|
35
|
+
export type DurableTaskEventAck = DurableTaskEventRunAck | DurableTaskEventMemoAck | DurableTaskEventWaitForAck;
|
|
36
|
+
export interface DurableTaskEventLogEntryResult {
|
|
37
|
+
durableTaskExternalId: string;
|
|
38
|
+
nodeId: number;
|
|
39
|
+
payload: Record<string, unknown> | undefined;
|
|
40
|
+
}
|
|
41
|
+
export interface WaitForEvent {
|
|
42
|
+
kind: 'waitFor';
|
|
43
|
+
waitForConditions: DurableEventListenerConditions;
|
|
44
|
+
}
|
|
45
|
+
export interface RunChildrenEvent {
|
|
46
|
+
kind: 'runChildren';
|
|
47
|
+
triggerOpts: TriggerWorkflowRequest[];
|
|
48
|
+
}
|
|
49
|
+
export interface MemoEvent {
|
|
50
|
+
kind: 'memo';
|
|
51
|
+
memoKey: Uint8Array;
|
|
52
|
+
payload?: Uint8Array;
|
|
53
|
+
}
|
|
54
|
+
export type DurableTaskSendEvent = WaitForEvent | RunChildrenEvent | MemoEvent;
|
|
8
55
|
export declare class DurableListenerClient {
|
|
9
56
|
config: ClientConfig;
|
|
10
57
|
client: V1DispatcherClient;
|
|
11
58
|
logger: Logger;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
59
|
+
private _workerId;
|
|
60
|
+
private _running;
|
|
61
|
+
private _requestQueue;
|
|
62
|
+
private _requestNotify;
|
|
63
|
+
private _pendingEventAcks;
|
|
64
|
+
private _pendingCallbacks;
|
|
65
|
+
private _bufferedCompletions;
|
|
66
|
+
private _pendingEvictionAcks;
|
|
67
|
+
private _receiveAbort;
|
|
68
|
+
private _statusInterval;
|
|
69
|
+
private _startLock;
|
|
70
|
+
onServerEvict: ((durableTaskExternalId: string, invocationCount: number) => void) | undefined;
|
|
71
|
+
constructor(config: ClientConfig, channel: Channel, factory: ClientFactory);
|
|
72
|
+
get workerId(): string | undefined;
|
|
73
|
+
start(workerId: string): Promise<void>;
|
|
74
|
+
private _doStart;
|
|
75
|
+
ensureStarted(workerId: string): Promise<void>;
|
|
76
|
+
stop(): Promise<void>;
|
|
77
|
+
private _connect;
|
|
78
|
+
private _streamLoop;
|
|
79
|
+
private _requestIterator;
|
|
80
|
+
private _enqueueRequest;
|
|
81
|
+
private _startStatusPolling;
|
|
82
|
+
private _pollWorkerStatus;
|
|
83
|
+
private _failPendingAcks;
|
|
84
|
+
private _failAllPending;
|
|
85
|
+
private _handleResponse;
|
|
86
|
+
sendEvent(durableTaskExternalId: string, invocationCount: number, event: RunChildrenEvent): Promise<DurableTaskEventRunAck>;
|
|
87
|
+
sendEvent(durableTaskExternalId: string, invocationCount: number, event: WaitForEvent): Promise<DurableTaskEventWaitForAck>;
|
|
88
|
+
sendEvent(durableTaskExternalId: string, invocationCount: number, event: MemoEvent): Promise<DurableTaskEventMemoAck>;
|
|
89
|
+
waitForCallback(durableTaskExternalId: string, invocationCount: number, branchId: number, nodeId: number, opts?: {
|
|
90
|
+
signal?: AbortSignal;
|
|
91
|
+
}): Promise<DurableTaskEventLogEntryResult>;
|
|
92
|
+
cleanupTaskState(durableTaskExternalId: string, invocationCount: number): void;
|
|
93
|
+
sendEvictInvocation(durableTaskExternalId: string, invocationCount: number, reason?: string): Promise<void>;
|
|
94
|
+
sendMemoCompletedNotification(durableTaskExternalId: string, nodeId: number, branchId: number, invocationCount: number, memoKey: Uint8Array, memoResultPayload?: Uint8Array): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated Legacy backward-compat: uses the old unary RegisterDurableEvent RPC.
|
|
97
|
+
*/
|
|
98
|
+
registerDurableEvent(request: {
|
|
99
|
+
taskId: string;
|
|
100
|
+
signalKey: string;
|
|
101
|
+
sleepConditions: Array<SleepMatchCondition>;
|
|
102
|
+
userEventConditions: Array<UserEventMatchCondition>;
|
|
103
|
+
}): Promise<RegisterDurableEventResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* @deprecated Legacy backward-compat: uses the old streaming ListenForDurableEvent RPC.
|
|
106
|
+
*/
|
|
15
107
|
subscribe(request: {
|
|
16
108
|
taskId: string;
|
|
17
109
|
signalKey: string;
|
|
18
|
-
}):
|
|
110
|
+
}): LegacyDurableEventStreamable;
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated Legacy backward-compat: subscribes and waits for a single result.
|
|
113
|
+
*/
|
|
19
114
|
result(request: {
|
|
20
115
|
taskId: string;
|
|
21
116
|
signalKey: string;
|
|
22
117
|
}, opts?: {
|
|
23
118
|
signal?: AbortSignal;
|
|
24
|
-
}): Promise<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
119
|
+
}): Promise<DurableEvent>;
|
|
120
|
+
private _legacyPooledListener;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated Legacy support for the old streaming ListenForDurableEvent RPC.
|
|
124
|
+
*/
|
|
125
|
+
export declare class LegacyDurableEventStreamable {
|
|
126
|
+
responseEmitter: EventEmitter<[never]>;
|
|
127
|
+
private _onCleanup;
|
|
128
|
+
constructor(onCleanup: () => void);
|
|
129
|
+
get(opts?: {
|
|
130
|
+
signal?: AbortSignal;
|
|
131
|
+
}): Promise<DurableEvent>;
|
|
31
132
|
}
|