eventTrigger() jsdocs
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@trigger.dev/sdk": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
eventTrigger() jsdocs
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const EventMatcherSchema = z.union([
|
const EventMatcherSchema = z.union([
|
||||||
|
/** Match against a string */
|
||||||
z.array(z.string()),
|
z.array(z.string()),
|
||||||
|
/** Match against a number */
|
||||||
z.array(z.number()),
|
z.array(z.number()),
|
||||||
|
/** Match against a boolean */
|
||||||
z.array(z.boolean()),
|
z.array(z.boolean()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
type EventMatcher = z.infer<typeof EventMatcherSchema>;
|
type EventMatcher = z.infer<typeof EventMatcherSchema>;
|
||||||
|
|
||||||
|
/** A filter for matching against data */
|
||||||
export type EventFilter = { [key: string]: EventMatcher | EventFilter };
|
export type EventFilter = { [key: string]: EventMatcher | EventFilter };
|
||||||
|
|
||||||
export const EventFilterSchema: z.ZodType<EventFilter> = z.lazy(() =>
|
export const EventFilterSchema: z.ZodType<EventFilter> = z.lazy(() =>
|
||||||
|
|||||||
@@ -54,13 +54,41 @@ export class EventTrigger<TEventSpecification extends EventSpecification<any>>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Configuration options for an EventTrigger */
|
||||||
type TriggerOptions<TEvent> = {
|
type TriggerOptions<TEvent> = {
|
||||||
|
/** The name of the event you are subscribing to. Must be an exact match (case sensitive). */
|
||||||
name: string;
|
name: string;
|
||||||
|
/** A [Zod](https://trigger.dev/docs/documentation/guides/zod) schema that defines the shape of the event payload.
|
||||||
|
* The default is `z.any()` which is `any`.
|
||||||
|
* */
|
||||||
schema?: z.Schema<TEvent>;
|
schema?: z.Schema<TEvent>;
|
||||||
|
/** You can use this to filter events based on the source. */
|
||||||
source?: string;
|
source?: string;
|
||||||
|
/** Used to filter which events trigger the Job
|
||||||
|
* @example
|
||||||
|
* filter:
|
||||||
|
* ```ts
|
||||||
|
* {
|
||||||
|
* name: ["John", "Jane"],
|
||||||
|
* age: [18, 21]
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* This filter would match against an event with the following data:
|
||||||
|
* ```json
|
||||||
|
* {
|
||||||
|
* "name": "Jane",
|
||||||
|
* "age": 18,
|
||||||
|
* "location": "San Francisco"
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
filter?: EventFilter;
|
filter?: EventFilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** `eventTrigger()` is set as a [Job's trigger](https://trigger.dev/docs/sdk/job) to subscribe to an event a Job from [a sent event](https://trigger.dev/docs/sdk/triggerclient/instancemethods/sendevent)
|
||||||
|
* @param options options for the EventTrigger
|
||||||
|
*/
|
||||||
export function eventTrigger<TEvent extends any = any>(
|
export function eventTrigger<TEvent extends any = any>(
|
||||||
options: TriggerOptions<TEvent>
|
options: TriggerOptions<TEvent>
|
||||||
): Trigger<EventSpecification<TEvent>> {
|
): Trigger<EventSpecification<TEvent>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user