@abinnovision/nestjs-hatchet 0.8.0-beta.4 → 0.8.0-beta.5
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 +6 -6
- package/dist/abstracts/hosts.d.cts +70 -0
- package/dist/abstracts/hosts.d.mts +70 -0
- package/dist/abstracts/index.d.cts +1 -0
- package/dist/abstracts/index.d.mts +1 -0
- package/dist/client/client.cjs +34 -21
- package/dist/client/client.d.cts +70 -0
- package/dist/client/client.d.mts +70 -0
- package/dist/client/client.mjs +34 -21
- package/dist/client/index.d.cts +1 -0
- package/dist/client/index.d.mts +1 -0
- package/dist/events/event-definition.d.cts +92 -0
- package/dist/events/event-definition.d.mts +92 -0
- package/dist/events/index.d.cts +1 -0
- package/dist/events/index.d.mts +1 -0
- package/dist/exceptions/event-payload-malformed.exception.d.cts +17 -0
- package/dist/exceptions/event-payload-malformed.exception.d.mts +17 -0
- package/dist/exceptions/hatchet.exception.d.cts +14 -0
- package/dist/exceptions/hatchet.exception.d.mts +14 -0
- package/dist/exceptions/index.d.cts +4 -0
- package/dist/exceptions/index.d.mts +4 -0
- package/dist/exceptions/input-validation-failed.exception.d.cts +20 -0
- package/dist/exceptions/input-validation-failed.exception.d.mts +20 -0
- package/dist/exceptions/validation-issue.d.cts +34 -0
- package/dist/exceptions/validation-issue.d.mts +34 -0
- package/dist/execution/context/factory.d.cts +1 -0
- package/dist/execution/context/factory.d.mts +1 -0
- package/dist/execution/context/index.d.cts +1 -0
- package/dist/execution/context/index.d.mts +1 -0
- package/dist/execution/context/types.d.cts +112 -0
- package/dist/execution/context/types.d.mts +112 -0
- package/dist/execution/host-run/adapter-factory.d.cts +1 -0
- package/dist/execution/host-run/adapter-factory.d.mts +1 -0
- package/dist/execution/host-run/function-type.d.cts +28 -0
- package/dist/execution/host-run/function-type.d.mts +28 -0
- package/dist/execution/host-run/index.d.cts +1 -0
- package/dist/execution/host-run/index.d.mts +1 -0
- package/dist/execution/index.d.cts +2 -0
- package/dist/execution/index.d.mts +2 -0
- package/dist/hatchet.module-config.d.cts +33 -0
- package/dist/hatchet.module-config.d.mts +33 -0
- package/dist/hatchet.module.d.cts +26 -0
- package/dist/hatchet.module.d.mts +26 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.mts +19 -0
- package/dist/interceptor/index.d.cts +1 -0
- package/dist/interceptor/index.d.mts +1 -0
- package/dist/interceptor/interceptor.d.cts +11 -0
- package/dist/interceptor/interceptor.d.mts +11 -0
- package/dist/metadata/decorators/host.decorator.d.cts +22 -0
- package/dist/metadata/decorators/host.decorator.d.mts +22 -0
- package/dist/metadata/decorators/index.d.cts +3 -0
- package/dist/metadata/decorators/index.d.mts +3 -0
- package/dist/metadata/decorators/task.decorator.d.cts +10 -0
- package/dist/metadata/decorators/task.decorator.d.mts +10 -0
- package/dist/metadata/decorators/workflow-task.decorator.d.cts +14 -0
- package/dist/metadata/decorators/workflow-task.decorator.d.mts +14 -0
- package/dist/metadata/index.d.cts +3 -0
- package/dist/metadata/index.d.mts +3 -0
- package/dist/metadata/translator.d.cts +1 -0
- package/dist/metadata/translator.d.mts +1 -0
- package/dist/references/helpers.d.cts +16 -0
- package/dist/references/helpers.d.mts +16 -0
- package/dist/references/index.d.cts +3 -0
- package/dist/references/index.d.mts +3 -0
- package/dist/references/refs.d.cts +31 -0
- package/dist/references/refs.d.mts +31 -0
- package/dist/references/{shared.d.ts → shared.d.cts} +26 -29
- package/dist/references/shared.d.mts +169 -0
- package/dist/sdk/{types.d.ts → types.d.cts} +5 -2
- package/dist/sdk/types.d.mts +10 -0
- package/dist/sdk-export/index.d.cts +1 -0
- package/dist/sdk-export/index.d.mts +1 -0
- package/package.json +12 -11
- package/dist/abstracts/hosts.d.ts +0 -66
- package/dist/abstracts/index.d.ts +0 -1
- package/dist/client/client.d.ts +0 -48
- package/dist/client/index.d.ts +0 -1
- package/dist/events/event-definition.d.ts +0 -88
- package/dist/events/index.d.ts +0 -2
- package/dist/exceptions/event-payload-malformed.exception.d.ts +0 -13
- package/dist/exceptions/hatchet.exception.d.ts +0 -11
- package/dist/exceptions/index.d.ts +0 -4
- package/dist/exceptions/input-validation-failed.exception.d.ts +0 -16
- package/dist/exceptions/validation-issue.d.ts +0 -30
- package/dist/execution/context/factory.d.ts +0 -22
- package/dist/execution/context/index.d.ts +0 -4
- package/dist/execution/context/types.d.ts +0 -108
- package/dist/execution/host-run/adapter-factory.d.ts +0 -12
- package/dist/execution/host-run/function-type.d.ts +0 -24
- package/dist/execution/host-run/index.d.ts +0 -2
- package/dist/execution/index.d.ts +0 -2
- package/dist/explorer/declaration-builder.service.d.ts +0 -70
- package/dist/explorer/index.d.ts +0 -1
- package/dist/explorer/worker-management.service.d.ts +0 -39
- package/dist/hatchet.module-config.d.ts +0 -31
- package/dist/hatchet.module.d.ts +0 -23
- package/dist/index.d.ts +0 -10
- package/dist/interceptor/index.d.ts +0 -1
- package/dist/interceptor/interceptor.d.ts +0 -13
- package/dist/internal/registrations.d.ts +0 -19
- package/dist/metadata/accessor.d.ts +0 -33
- package/dist/metadata/decorators/host.decorator.d.ts +0 -19
- package/dist/metadata/decorators/index.d.ts +0 -6
- package/dist/metadata/decorators/task.decorator.d.ts +0 -6
- package/dist/metadata/decorators/workflow-task.decorator.d.ts +0 -10
- package/dist/metadata/index.d.ts +0 -6
- package/dist/metadata/keys.d.ts +0 -3
- package/dist/metadata/translator.d.ts +0 -10
- package/dist/references/helpers.d.ts +0 -27
- package/dist/references/index.d.ts +0 -3
- package/dist/references/refs.d.ts +0 -27
- package/dist/sdk/hatchet-client.factory.d.ts +0 -5
- package/dist/sdk/index.d.ts +0 -1
- package/dist/sdk-export/index.d.ts +0 -7
package/README.md
CHANGED
|
@@ -176,11 +176,11 @@ await client.emit(UserCreatedEvent, {
|
|
|
176
176
|
|
|
177
177
|
### Client
|
|
178
178
|
|
|
179
|
-
| Method
|
|
180
|
-
|
|
|
181
|
-
| `client.run(ref, input, opts?)`
|
|
182
|
-
| `client.emit(event, payload)`
|
|
183
|
-
| `client.emitBulk(event, payloads)`
|
|
179
|
+
| Method | Description |
|
|
180
|
+
| ----------------------------------------- | ---------------------------------------------- |
|
|
181
|
+
| `client.run(ref, input, opts?)` | Execute task/workflow |
|
|
182
|
+
| `client.emit(event, payload \| payloads)` | Emit one or many events |
|
|
183
|
+
| `client.emitBulk(event, payloads)` | Emit multiple events (deprecated — use `emit`) |
|
|
184
184
|
|
|
185
185
|
### Context Types
|
|
186
186
|
|
|
@@ -212,7 +212,7 @@ const result = await runRef.output; // Await when needed
|
|
|
212
212
|
### Bulk Event Emission
|
|
213
213
|
|
|
214
214
|
```typescript
|
|
215
|
-
await client.
|
|
215
|
+
await client.emit(OrderEvent, [
|
|
216
216
|
{ orderId: "1", total: 100 },
|
|
217
217
|
{ orderId: "2", total: 200 },
|
|
218
218
|
]);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { InputType } from "@hatchet-dev/typescript-sdk";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/abstracts/hosts.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Interface for classes that provide a schema for their input.
|
|
7
|
+
*/
|
|
8
|
+
interface InputSchemaProvider<T> {
|
|
9
|
+
/**
|
|
10
|
+
* Returns the schema for the input of the host.
|
|
11
|
+
* If undefined, the input is not validated.
|
|
12
|
+
*/
|
|
13
|
+
inputSchema: () => StandardSchemaV1<InputType, T> | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Marker class for Hatchet workflow host classes.
|
|
17
|
+
*/
|
|
18
|
+
declare abstract class WorkflowHost<I> implements InputSchemaProvider<I> {
|
|
19
|
+
readonly inputSchema: InputSchemaProvider<I>["inputSchema"];
|
|
20
|
+
readonly __workflow_host_brand: void;
|
|
21
|
+
readonly __workflow_host_input: I;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor for the WorkflowHost class.
|
|
24
|
+
*
|
|
25
|
+
* @param inputSchema
|
|
26
|
+
* @protected
|
|
27
|
+
*/
|
|
28
|
+
protected constructor(inputSchema: InputSchemaProvider<I>["inputSchema"]);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Marker class for Hatchet task host classes.
|
|
32
|
+
*/
|
|
33
|
+
declare abstract class TaskHost<I> implements InputSchemaProvider<I> {
|
|
34
|
+
readonly inputSchema: InputSchemaProvider<I>["inputSchema"];
|
|
35
|
+
readonly __task_host_brand: void;
|
|
36
|
+
readonly __task_host_input: I;
|
|
37
|
+
/**
|
|
38
|
+
* Constructor for the TaskHost class.
|
|
39
|
+
*
|
|
40
|
+
* @param inputSchema
|
|
41
|
+
* @protected
|
|
42
|
+
*/
|
|
43
|
+
protected constructor(inputSchema: InputSchemaProvider<I>["inputSchema"]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new WorkflowHost class with the provided input schema.
|
|
47
|
+
*
|
|
48
|
+
* @param input The input schema.
|
|
49
|
+
*/
|
|
50
|
+
declare function workflowHost<I>(input?: ReturnType<InputSchemaProvider<I>["inputSchema"]>): {
|
|
51
|
+
new (): {
|
|
52
|
+
readonly __workflow_host_brand: void;
|
|
53
|
+
readonly __workflow_host_input: I;
|
|
54
|
+
readonly inputSchema: () => StandardSchemaV1<import("@hatchet-dev/typescript-sdk").JsonObject, I> | undefined;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new TaskHost class with the provided input schema.
|
|
59
|
+
*
|
|
60
|
+
* @param input The input schema.
|
|
61
|
+
*/
|
|
62
|
+
declare function taskHost<I>(input?: ReturnType<InputSchemaProvider<I>["inputSchema"]>): {
|
|
63
|
+
new (): {
|
|
64
|
+
readonly __task_host_brand: void;
|
|
65
|
+
readonly __task_host_input: I;
|
|
66
|
+
readonly inputSchema: () => StandardSchemaV1<import("@hatchet-dev/typescript-sdk").JsonObject, I> | undefined;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
export { InputSchemaProvider, TaskHost, WorkflowHost, taskHost, workflowHost };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { InputType } from "@hatchet-dev/typescript-sdk";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/abstracts/hosts.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Interface for classes that provide a schema for their input.
|
|
7
|
+
*/
|
|
8
|
+
interface InputSchemaProvider<T> {
|
|
9
|
+
/**
|
|
10
|
+
* Returns the schema for the input of the host.
|
|
11
|
+
* If undefined, the input is not validated.
|
|
12
|
+
*/
|
|
13
|
+
inputSchema: () => StandardSchemaV1<InputType, T> | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Marker class for Hatchet workflow host classes.
|
|
17
|
+
*/
|
|
18
|
+
declare abstract class WorkflowHost<I> implements InputSchemaProvider<I> {
|
|
19
|
+
readonly inputSchema: InputSchemaProvider<I>["inputSchema"];
|
|
20
|
+
readonly __workflow_host_brand: void;
|
|
21
|
+
readonly __workflow_host_input: I;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor for the WorkflowHost class.
|
|
24
|
+
*
|
|
25
|
+
* @param inputSchema
|
|
26
|
+
* @protected
|
|
27
|
+
*/
|
|
28
|
+
protected constructor(inputSchema: InputSchemaProvider<I>["inputSchema"]);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Marker class for Hatchet task host classes.
|
|
32
|
+
*/
|
|
33
|
+
declare abstract class TaskHost<I> implements InputSchemaProvider<I> {
|
|
34
|
+
readonly inputSchema: InputSchemaProvider<I>["inputSchema"];
|
|
35
|
+
readonly __task_host_brand: void;
|
|
36
|
+
readonly __task_host_input: I;
|
|
37
|
+
/**
|
|
38
|
+
* Constructor for the TaskHost class.
|
|
39
|
+
*
|
|
40
|
+
* @param inputSchema
|
|
41
|
+
* @protected
|
|
42
|
+
*/
|
|
43
|
+
protected constructor(inputSchema: InputSchemaProvider<I>["inputSchema"]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new WorkflowHost class with the provided input schema.
|
|
47
|
+
*
|
|
48
|
+
* @param input The input schema.
|
|
49
|
+
*/
|
|
50
|
+
declare function workflowHost<I>(input?: ReturnType<InputSchemaProvider<I>["inputSchema"]>): {
|
|
51
|
+
new (): {
|
|
52
|
+
readonly __workflow_host_brand: void;
|
|
53
|
+
readonly __workflow_host_input: I;
|
|
54
|
+
readonly inputSchema: () => StandardSchemaV1<import("@hatchet-dev/typescript-sdk").JsonObject, I> | undefined;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new TaskHost class with the provided input schema.
|
|
59
|
+
*
|
|
60
|
+
* @param input The input schema.
|
|
61
|
+
*/
|
|
62
|
+
declare function taskHost<I>(input?: ReturnType<InputSchemaProvider<I>["inputSchema"]>): {
|
|
63
|
+
new (): {
|
|
64
|
+
readonly __task_host_brand: void;
|
|
65
|
+
readonly __task_host_input: I;
|
|
66
|
+
readonly inputSchema: () => StandardSchemaV1<import("@hatchet-dev/typescript-sdk").JsonObject, I> | undefined;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
//#endregion
|
|
70
|
+
export { InputSchemaProvider, TaskHost, WorkflowHost, taskHost, workflowHost };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { InputSchemaProvider, TaskHost, WorkflowHost, taskHost, workflowHost } from "./hosts.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { InputSchemaProvider, TaskHost, WorkflowHost, taskHost, workflowHost } from "./hosts.mjs";
|
package/dist/client/client.cjs
CHANGED
|
@@ -26,18 +26,45 @@ var Client = class {
|
|
|
26
26
|
return this.client;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Emit
|
|
29
|
+
* Emit one or many events of the same type.
|
|
30
|
+
*
|
|
31
|
+
* Pass a single payload to emit one event, or an array of payloads to emit
|
|
32
|
+
* many at once. The return type adjusts accordingly: a single {@link Event}
|
|
33
|
+
* for a single input, or an array of {@link Event} for an array of inputs.
|
|
30
34
|
*
|
|
31
35
|
* @param event The event definition to emit.
|
|
32
|
-
* @param input
|
|
36
|
+
* @param input A single event payload, or an array of payloads (each must
|
|
37
|
+
* match the event's schema).
|
|
33
38
|
* @param options Optional emit configuration.
|
|
34
|
-
* @returns The emitted event.
|
|
39
|
+
* @returns The emitted event, or an array of emitted events.
|
|
35
40
|
*
|
|
36
41
|
* @example
|
|
37
42
|
* ```typescript
|
|
43
|
+
* // Single event
|
|
38
44
|
* await client.emit(UserCreatedEvent, { userId: "123", email: "user@example.com" });
|
|
39
45
|
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Multiple events
|
|
50
|
+
* await client.emit(OrderPlacedEvent, [
|
|
51
|
+
* { orderId: "1", userId: "123", total: 100 },
|
|
52
|
+
* { orderId: "2", userId: "456", total: 200 },
|
|
53
|
+
* ]);
|
|
54
|
+
* ```
|
|
40
55
|
*/ async emit(event, input, options) {
|
|
56
|
+
if (Array.isArray(input)) {
|
|
57
|
+
if (input.length === 0) return [];
|
|
58
|
+
return (await this.client.events.bulkPush(event.name, input.map((single) => ({
|
|
59
|
+
payload: {
|
|
60
|
+
...single,
|
|
61
|
+
[require_event_definition.EVENT_MARKER]: event.name
|
|
62
|
+
},
|
|
63
|
+
...options?.additionalMetadata !== void 0 && { additionalMetadata: options.additionalMetadata },
|
|
64
|
+
...options?.priority !== void 0 && { priority: options.priority },
|
|
65
|
+
...options?.scope !== void 0 && { scope: options.scope }
|
|
66
|
+
})), options)).events;
|
|
67
|
+
}
|
|
41
68
|
return await this.client.events.push(event.name, {
|
|
42
69
|
...input,
|
|
43
70
|
[require_event_definition.EVENT_MARKER]: event.name
|
|
@@ -46,29 +73,15 @@ var Client = class {
|
|
|
46
73
|
/**
|
|
47
74
|
* Emit multiple events of the same type.
|
|
48
75
|
*
|
|
76
|
+
* @deprecated Use {@link Client.emit} with an array of inputs instead. This
|
|
77
|
+
* alias forwards to `emit` and will be removed in a future major version.
|
|
78
|
+
*
|
|
49
79
|
* @param event The event definition to emit.
|
|
50
80
|
* @param inputs Array of event payloads.
|
|
51
81
|
* @param options Optional emit configuration.
|
|
52
82
|
* @returns Array of emitted events.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* await client.emitBulk(OrderPlacedEvent, [
|
|
57
|
-
* { orderId: "1", userId: "123", total: 100 },
|
|
58
|
-
* { orderId: "2", userId: "456", total: 200 },
|
|
59
|
-
* ]);
|
|
60
|
-
* ```
|
|
61
83
|
*/ async emitBulk(event, inputs, options) {
|
|
62
|
-
|
|
63
|
-
return (await this.client.events.bulkPush(event.name, inputs.map((input) => ({
|
|
64
|
-
payload: {
|
|
65
|
-
...input,
|
|
66
|
-
[require_event_definition.EVENT_MARKER]: event.name
|
|
67
|
-
},
|
|
68
|
-
...options?.additionalMetadata !== void 0 && { additionalMetadata: options.additionalMetadata },
|
|
69
|
-
...options?.priority !== void 0 && { priority: options.priority },
|
|
70
|
-
...options?.scope !== void 0 && { scope: options.scope }
|
|
71
|
-
})), options)).events;
|
|
84
|
+
return await this.emit(event, inputs, options);
|
|
72
85
|
}
|
|
73
86
|
};
|
|
74
87
|
Client = _ts_decorate([
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AnyEventDefinition, EventInput } from "../events/event-definition.cjs";
|
|
2
|
+
import { HostRunFn } from "../execution/host-run/function-type.cjs";
|
|
3
|
+
import { HatchetClient } from "@hatchet-dev/typescript-sdk";
|
|
4
|
+
|
|
5
|
+
//#region src/client/client.d.ts
|
|
6
|
+
type EventClient = HatchetClient["events"];
|
|
7
|
+
type EventEmitOptions = Parameters<EventClient["push"]>[2];
|
|
8
|
+
type Event = Awaited<ReturnType<EventClient["push"]>>;
|
|
9
|
+
/**
|
|
10
|
+
* Input accepted by {@link Client.emit} — a single event payload or an array of them.
|
|
11
|
+
*/
|
|
12
|
+
type EventEmitInput<E extends AnyEventDefinition> = EventInput<E> | EventInput<E>[];
|
|
13
|
+
/**
|
|
14
|
+
* Return type of {@link Client.emit}: an array of events when an array of inputs is
|
|
15
|
+
* provided, otherwise a single event.
|
|
16
|
+
*/
|
|
17
|
+
type EventEmitReturn<E extends AnyEventDefinition, I extends EventEmitInput<E>> = I extends EventInput<E>[] ? Event[] : Event;
|
|
18
|
+
declare class Client {
|
|
19
|
+
private readonly client;
|
|
20
|
+
readonly run: HostRunFn;
|
|
21
|
+
constructor(client: HatchetClient);
|
|
22
|
+
/**
|
|
23
|
+
* Access to the underlying HatchetClient SDK.
|
|
24
|
+
* Use for advanced features not wrapped by this library.
|
|
25
|
+
*/
|
|
26
|
+
get sdk(): HatchetClient;
|
|
27
|
+
/**
|
|
28
|
+
* Emit one or many events of the same type.
|
|
29
|
+
*
|
|
30
|
+
* Pass a single payload to emit one event, or an array of payloads to emit
|
|
31
|
+
* many at once. The return type adjusts accordingly: a single {@link Event}
|
|
32
|
+
* for a single input, or an array of {@link Event} for an array of inputs.
|
|
33
|
+
*
|
|
34
|
+
* @param event The event definition to emit.
|
|
35
|
+
* @param input A single event payload, or an array of payloads (each must
|
|
36
|
+
* match the event's schema).
|
|
37
|
+
* @param options Optional emit configuration.
|
|
38
|
+
* @returns The emitted event, or an array of emitted events.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Single event
|
|
43
|
+
* await client.emit(UserCreatedEvent, { userId: "123", email: "user@example.com" });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Multiple events
|
|
49
|
+
* await client.emit(OrderPlacedEvent, [
|
|
50
|
+
* { orderId: "1", userId: "123", total: 100 },
|
|
51
|
+
* { orderId: "2", userId: "456", total: 200 },
|
|
52
|
+
* ]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
emit<E extends AnyEventDefinition, I extends EventEmitInput<E>>(event: E, input: I, options?: EventEmitOptions): Promise<EventEmitReturn<E, I>>;
|
|
56
|
+
/**
|
|
57
|
+
* Emit multiple events of the same type.
|
|
58
|
+
*
|
|
59
|
+
* @deprecated Use {@link Client.emit} with an array of inputs instead. This
|
|
60
|
+
* alias forwards to `emit` and will be removed in a future major version.
|
|
61
|
+
*
|
|
62
|
+
* @param event The event definition to emit.
|
|
63
|
+
* @param inputs Array of event payloads.
|
|
64
|
+
* @param options Optional emit configuration.
|
|
65
|
+
* @returns Array of emitted events.
|
|
66
|
+
*/
|
|
67
|
+
emitBulk<E extends AnyEventDefinition>(event: E, inputs: EventInput<E>[], options?: EventEmitOptions): Promise<Event[]>;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { Client };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AnyEventDefinition, EventInput } from "../events/event-definition.mjs";
|
|
2
|
+
import { HostRunFn } from "../execution/host-run/function-type.mjs";
|
|
3
|
+
import { HatchetClient } from "@hatchet-dev/typescript-sdk";
|
|
4
|
+
|
|
5
|
+
//#region src/client/client.d.ts
|
|
6
|
+
type EventClient = HatchetClient["events"];
|
|
7
|
+
type EventEmitOptions = Parameters<EventClient["push"]>[2];
|
|
8
|
+
type Event = Awaited<ReturnType<EventClient["push"]>>;
|
|
9
|
+
/**
|
|
10
|
+
* Input accepted by {@link Client.emit} — a single event payload or an array of them.
|
|
11
|
+
*/
|
|
12
|
+
type EventEmitInput<E extends AnyEventDefinition> = EventInput<E> | EventInput<E>[];
|
|
13
|
+
/**
|
|
14
|
+
* Return type of {@link Client.emit}: an array of events when an array of inputs is
|
|
15
|
+
* provided, otherwise a single event.
|
|
16
|
+
*/
|
|
17
|
+
type EventEmitReturn<E extends AnyEventDefinition, I extends EventEmitInput<E>> = I extends EventInput<E>[] ? Event[] : Event;
|
|
18
|
+
declare class Client {
|
|
19
|
+
private readonly client;
|
|
20
|
+
readonly run: HostRunFn;
|
|
21
|
+
constructor(client: HatchetClient);
|
|
22
|
+
/**
|
|
23
|
+
* Access to the underlying HatchetClient SDK.
|
|
24
|
+
* Use for advanced features not wrapped by this library.
|
|
25
|
+
*/
|
|
26
|
+
get sdk(): HatchetClient;
|
|
27
|
+
/**
|
|
28
|
+
* Emit one or many events of the same type.
|
|
29
|
+
*
|
|
30
|
+
* Pass a single payload to emit one event, or an array of payloads to emit
|
|
31
|
+
* many at once. The return type adjusts accordingly: a single {@link Event}
|
|
32
|
+
* for a single input, or an array of {@link Event} for an array of inputs.
|
|
33
|
+
*
|
|
34
|
+
* @param event The event definition to emit.
|
|
35
|
+
* @param input A single event payload, or an array of payloads (each must
|
|
36
|
+
* match the event's schema).
|
|
37
|
+
* @param options Optional emit configuration.
|
|
38
|
+
* @returns The emitted event, or an array of emitted events.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Single event
|
|
43
|
+
* await client.emit(UserCreatedEvent, { userId: "123", email: "user@example.com" });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Multiple events
|
|
49
|
+
* await client.emit(OrderPlacedEvent, [
|
|
50
|
+
* { orderId: "1", userId: "123", total: 100 },
|
|
51
|
+
* { orderId: "2", userId: "456", total: 200 },
|
|
52
|
+
* ]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
emit<E extends AnyEventDefinition, I extends EventEmitInput<E>>(event: E, input: I, options?: EventEmitOptions): Promise<EventEmitReturn<E, I>>;
|
|
56
|
+
/**
|
|
57
|
+
* Emit multiple events of the same type.
|
|
58
|
+
*
|
|
59
|
+
* @deprecated Use {@link Client.emit} with an array of inputs instead. This
|
|
60
|
+
* alias forwards to `emit` and will be removed in a future major version.
|
|
61
|
+
*
|
|
62
|
+
* @param event The event definition to emit.
|
|
63
|
+
* @param inputs Array of event payloads.
|
|
64
|
+
* @param options Optional emit configuration.
|
|
65
|
+
* @returns Array of emitted events.
|
|
66
|
+
*/
|
|
67
|
+
emitBulk<E extends AnyEventDefinition>(event: E, inputs: EventInput<E>[], options?: EventEmitOptions): Promise<Event[]>;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { Client };
|
package/dist/client/client.mjs
CHANGED
|
@@ -26,18 +26,45 @@ var Client = class {
|
|
|
26
26
|
return this.client;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Emit
|
|
29
|
+
* Emit one or many events of the same type.
|
|
30
|
+
*
|
|
31
|
+
* Pass a single payload to emit one event, or an array of payloads to emit
|
|
32
|
+
* many at once. The return type adjusts accordingly: a single {@link Event}
|
|
33
|
+
* for a single input, or an array of {@link Event} for an array of inputs.
|
|
30
34
|
*
|
|
31
35
|
* @param event The event definition to emit.
|
|
32
|
-
* @param input
|
|
36
|
+
* @param input A single event payload, or an array of payloads (each must
|
|
37
|
+
* match the event's schema).
|
|
33
38
|
* @param options Optional emit configuration.
|
|
34
|
-
* @returns The emitted event.
|
|
39
|
+
* @returns The emitted event, or an array of emitted events.
|
|
35
40
|
*
|
|
36
41
|
* @example
|
|
37
42
|
* ```typescript
|
|
43
|
+
* // Single event
|
|
38
44
|
* await client.emit(UserCreatedEvent, { userId: "123", email: "user@example.com" });
|
|
39
45
|
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Multiple events
|
|
50
|
+
* await client.emit(OrderPlacedEvent, [
|
|
51
|
+
* { orderId: "1", userId: "123", total: 100 },
|
|
52
|
+
* { orderId: "2", userId: "456", total: 200 },
|
|
53
|
+
* ]);
|
|
54
|
+
* ```
|
|
40
55
|
*/ async emit(event, input, options) {
|
|
56
|
+
if (Array.isArray(input)) {
|
|
57
|
+
if (input.length === 0) return [];
|
|
58
|
+
return (await this.client.events.bulkPush(event.name, input.map((single) => ({
|
|
59
|
+
payload: {
|
|
60
|
+
...single,
|
|
61
|
+
[EVENT_MARKER]: event.name
|
|
62
|
+
},
|
|
63
|
+
...options?.additionalMetadata !== void 0 && { additionalMetadata: options.additionalMetadata },
|
|
64
|
+
...options?.priority !== void 0 && { priority: options.priority },
|
|
65
|
+
...options?.scope !== void 0 && { scope: options.scope }
|
|
66
|
+
})), options)).events;
|
|
67
|
+
}
|
|
41
68
|
return await this.client.events.push(event.name, {
|
|
42
69
|
...input,
|
|
43
70
|
[EVENT_MARKER]: event.name
|
|
@@ -46,29 +73,15 @@ var Client = class {
|
|
|
46
73
|
/**
|
|
47
74
|
* Emit multiple events of the same type.
|
|
48
75
|
*
|
|
76
|
+
* @deprecated Use {@link Client.emit} with an array of inputs instead. This
|
|
77
|
+
* alias forwards to `emit` and will be removed in a future major version.
|
|
78
|
+
*
|
|
49
79
|
* @param event The event definition to emit.
|
|
50
80
|
* @param inputs Array of event payloads.
|
|
51
81
|
* @param options Optional emit configuration.
|
|
52
82
|
* @returns Array of emitted events.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```typescript
|
|
56
|
-
* await client.emitBulk(OrderPlacedEvent, [
|
|
57
|
-
* { orderId: "1", userId: "123", total: 100 },
|
|
58
|
-
* { orderId: "2", userId: "456", total: 200 },
|
|
59
|
-
* ]);
|
|
60
|
-
* ```
|
|
61
83
|
*/ async emitBulk(event, inputs, options) {
|
|
62
|
-
|
|
63
|
-
return (await this.client.events.bulkPush(event.name, inputs.map((input) => ({
|
|
64
|
-
payload: {
|
|
65
|
-
...input,
|
|
66
|
-
[EVENT_MARKER]: event.name
|
|
67
|
-
},
|
|
68
|
-
...options?.additionalMetadata !== void 0 && { additionalMetadata: options.additionalMetadata },
|
|
69
|
-
...options?.priority !== void 0 && { priority: options.priority },
|
|
70
|
-
...options?.scope !== void 0 && { scope: options.scope }
|
|
71
|
-
})), options)).events;
|
|
84
|
+
return await this.emit(event, inputs, options);
|
|
72
85
|
}
|
|
73
86
|
};
|
|
74
87
|
Client = _ts_decorate([
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Client } from "./client.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { Client } from "./client.mjs";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/events/event-definition.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Marker embedded in event payload to identify an event type.
|
|
6
|
+
* Used by isCtx() type guard to determine which event triggered the workflow.
|
|
7
|
+
*/
|
|
8
|
+
declare const EVENT_MARKER = "__event_name";
|
|
9
|
+
/**
|
|
10
|
+
* Type-safe event definition.
|
|
11
|
+
* Use with Client.emit() to publish events.
|
|
12
|
+
*
|
|
13
|
+
* @template TName The literal string type of the event name.
|
|
14
|
+
* @template TSchema The StandardSchema type for input validation.
|
|
15
|
+
*/
|
|
16
|
+
declare class EventDefinition<TName extends string, TSchema extends StandardSchemaV1> {
|
|
17
|
+
readonly name: TName;
|
|
18
|
+
readonly schema: TSchema;
|
|
19
|
+
/**
|
|
20
|
+
* Phantom types for input/output inference.
|
|
21
|
+
* Do not access at runtime - will throw.
|
|
22
|
+
*/
|
|
23
|
+
readonly __types: {
|
|
24
|
+
input: StandardSchemaV1.InferInput<TSchema>;
|
|
25
|
+
output: StandardSchemaV1.InferOutput<TSchema>;
|
|
26
|
+
};
|
|
27
|
+
constructor(name: TName, schema: TSchema);
|
|
28
|
+
/**
|
|
29
|
+
* Type guard: casts the context input to this event's schema output type
|
|
30
|
+
* without requiring the event marker to be present.
|
|
31
|
+
*
|
|
32
|
+
* Use this for externally sourced events that arrive without the marker
|
|
33
|
+
* injected by Client.emit(). Schema validation still runs and throws if
|
|
34
|
+
* the payload is malformed.
|
|
35
|
+
*
|
|
36
|
+
* @param ctx The context to check (TaskCtx, WorkflowCtx, HelperCtx, or SDK Context).
|
|
37
|
+
* @returns True if the context input is a non-null object that passes schema validation.
|
|
38
|
+
* @throws {EventPayloadMalformedException} If the payload fails schema validation.
|
|
39
|
+
*/
|
|
40
|
+
cast<C extends {
|
|
41
|
+
input: unknown;
|
|
42
|
+
}>(ctx: C): ctx is C & {
|
|
43
|
+
input: StandardSchemaV1.InferOutput<TSchema>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Type guard: checks if the context was triggered by this event.
|
|
47
|
+
* Validates the input against the event schema and throws if malformed.
|
|
48
|
+
*
|
|
49
|
+
* @param ctx The context to check (TaskCtx, WorkflowCtx, HelperCtx, or SDK Context).
|
|
50
|
+
* @returns True if the context input contains the event marker matching this event.
|
|
51
|
+
* @throws {EventPayloadMalformedException} If the event marker matches but the payload fails schema validation.
|
|
52
|
+
*/
|
|
53
|
+
isCtx<C extends {
|
|
54
|
+
input: unknown;
|
|
55
|
+
}>(ctx: C): ctx is C & {
|
|
56
|
+
input: StandardSchemaV1.InferOutput<TSchema> & {
|
|
57
|
+
[EVENT_MARKER]: TName;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Any event definition, used for generic constraints.
|
|
63
|
+
*/
|
|
64
|
+
type AnyEventDefinition = EventDefinition<string, StandardSchemaV1>;
|
|
65
|
+
/**
|
|
66
|
+
* Extracts the input type from an event definition.
|
|
67
|
+
*/
|
|
68
|
+
type EventInput<E extends AnyEventDefinition> = E["__types"]["input"];
|
|
69
|
+
/**
|
|
70
|
+
* Extracts the output type from an event definition.
|
|
71
|
+
*/
|
|
72
|
+
type EventOutput<E extends AnyEventDefinition> = E["__types"]["output"];
|
|
73
|
+
/**
|
|
74
|
+
* Factory function to create a type-safe event definition.
|
|
75
|
+
*
|
|
76
|
+
* @param name The event name (e.g., "user:created").
|
|
77
|
+
* @param schema A StandardSchema-compatible schema (e.g., Zod schema).
|
|
78
|
+
* @returns A new EventDefinition instance.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { z } from "zod";
|
|
83
|
+
*
|
|
84
|
+
* const UserCreatedEvent = defineEvent("user:created", z.object({
|
|
85
|
+
* userId: z.string(),
|
|
86
|
+
* email: z.string().email(),
|
|
87
|
+
* }));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare const defineEvent: <TName extends string, TSchema extends StandardSchemaV1>(name: TName, schema: TSchema) => EventDefinition<TName, TSchema>;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { AnyEventDefinition, EventDefinition, EventInput, EventOutput, defineEvent };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/events/event-definition.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Marker embedded in event payload to identify an event type.
|
|
6
|
+
* Used by isCtx() type guard to determine which event triggered the workflow.
|
|
7
|
+
*/
|
|
8
|
+
declare const EVENT_MARKER = "__event_name";
|
|
9
|
+
/**
|
|
10
|
+
* Type-safe event definition.
|
|
11
|
+
* Use with Client.emit() to publish events.
|
|
12
|
+
*
|
|
13
|
+
* @template TName The literal string type of the event name.
|
|
14
|
+
* @template TSchema The StandardSchema type for input validation.
|
|
15
|
+
*/
|
|
16
|
+
declare class EventDefinition<TName extends string, TSchema extends StandardSchemaV1> {
|
|
17
|
+
readonly name: TName;
|
|
18
|
+
readonly schema: TSchema;
|
|
19
|
+
/**
|
|
20
|
+
* Phantom types for input/output inference.
|
|
21
|
+
* Do not access at runtime - will throw.
|
|
22
|
+
*/
|
|
23
|
+
readonly __types: {
|
|
24
|
+
input: StandardSchemaV1.InferInput<TSchema>;
|
|
25
|
+
output: StandardSchemaV1.InferOutput<TSchema>;
|
|
26
|
+
};
|
|
27
|
+
constructor(name: TName, schema: TSchema);
|
|
28
|
+
/**
|
|
29
|
+
* Type guard: casts the context input to this event's schema output type
|
|
30
|
+
* without requiring the event marker to be present.
|
|
31
|
+
*
|
|
32
|
+
* Use this for externally sourced events that arrive without the marker
|
|
33
|
+
* injected by Client.emit(). Schema validation still runs and throws if
|
|
34
|
+
* the payload is malformed.
|
|
35
|
+
*
|
|
36
|
+
* @param ctx The context to check (TaskCtx, WorkflowCtx, HelperCtx, or SDK Context).
|
|
37
|
+
* @returns True if the context input is a non-null object that passes schema validation.
|
|
38
|
+
* @throws {EventPayloadMalformedException} If the payload fails schema validation.
|
|
39
|
+
*/
|
|
40
|
+
cast<C extends {
|
|
41
|
+
input: unknown;
|
|
42
|
+
}>(ctx: C): ctx is C & {
|
|
43
|
+
input: StandardSchemaV1.InferOutput<TSchema>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Type guard: checks if the context was triggered by this event.
|
|
47
|
+
* Validates the input against the event schema and throws if malformed.
|
|
48
|
+
*
|
|
49
|
+
* @param ctx The context to check (TaskCtx, WorkflowCtx, HelperCtx, or SDK Context).
|
|
50
|
+
* @returns True if the context input contains the event marker matching this event.
|
|
51
|
+
* @throws {EventPayloadMalformedException} If the event marker matches but the payload fails schema validation.
|
|
52
|
+
*/
|
|
53
|
+
isCtx<C extends {
|
|
54
|
+
input: unknown;
|
|
55
|
+
}>(ctx: C): ctx is C & {
|
|
56
|
+
input: StandardSchemaV1.InferOutput<TSchema> & {
|
|
57
|
+
[EVENT_MARKER]: TName;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Any event definition, used for generic constraints.
|
|
63
|
+
*/
|
|
64
|
+
type AnyEventDefinition = EventDefinition<string, StandardSchemaV1>;
|
|
65
|
+
/**
|
|
66
|
+
* Extracts the input type from an event definition.
|
|
67
|
+
*/
|
|
68
|
+
type EventInput<E extends AnyEventDefinition> = E["__types"]["input"];
|
|
69
|
+
/**
|
|
70
|
+
* Extracts the output type from an event definition.
|
|
71
|
+
*/
|
|
72
|
+
type EventOutput<E extends AnyEventDefinition> = E["__types"]["output"];
|
|
73
|
+
/**
|
|
74
|
+
* Factory function to create a type-safe event definition.
|
|
75
|
+
*
|
|
76
|
+
* @param name The event name (e.g., "user:created").
|
|
77
|
+
* @param schema A StandardSchema-compatible schema (e.g., Zod schema).
|
|
78
|
+
* @returns A new EventDefinition instance.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { z } from "zod";
|
|
83
|
+
*
|
|
84
|
+
* const UserCreatedEvent = defineEvent("user:created", z.object({
|
|
85
|
+
* userId: z.string(),
|
|
86
|
+
* email: z.string().email(),
|
|
87
|
+
* }));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare const defineEvent: <TName extends string, TSchema extends StandardSchemaV1>(name: TName, schema: TSchema) => EventDefinition<TName, TSchema>;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { AnyEventDefinition, EventDefinition, EventInput, EventOutput, defineEvent };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { AnyEventDefinition, EventDefinition, EventInput, EventOutput, defineEvent } from "./event-definition.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { AnyEventDefinition, EventDefinition, EventInput, EventOutput, defineEvent } from "./event-definition.mjs";
|