MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / DynamicTrigger

Class DynamicTrigger

packages/trigger-sdk/src/triggers/dynamic.ts:40–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39/** `DynamicTrigger` allows you to define a trigger that can be configured dynamically at runtime. */
40export class DynamicTrigger<
41 TEventSpec extends EventSpecification<any>,
42 TExternalSource extends ExternalSource<any, any, any>,
43> implements Trigger<TEventSpec>
44{
45 #client: TriggerClient;
46 #options: DynamicTriggerOptions<TEventSpec, TExternalSource>;
47 source: TExternalSource;
48
49 /** `DynamicTrigger` allows you to define a trigger that can be configured dynamically at runtime.
50 * @param client The `TriggerClient` instance to use for registering the trigger.
51 * @param options The options for the dynamic trigger.
52 * */
53 constructor(client: TriggerClient, options: DynamicTriggerOptions<TEventSpec, TExternalSource>) {
54 this.#client = client;
55 this.#options = options;
56 this.source = options.source;
57
58 client.attachDynamicTrigger(this);
59 }
60
61 toJSON(): TriggerMetadata {
62 return {
63 type: "dynamic",
64 id: this.#options.id,
65 };
66 }
67
68 get id() {
69 return this.#options.id;
70 }
71
72 get event() {
73 return this.#options.event;
74 }
75
76 // @internal
77 registeredTriggerForParams(
78 params: ExternalSourceParams<TExternalSource>,
79 options: { accountId?: string; filter?: EventFilter } = {}
80 ): RegisterTriggerBodyV2 {
81 const key = slugifyId(this.source.key(params));
82
83 return {
84 rule: {
85 event: this.event.name,
86 source: this.event.source,
87 payload: deepMergeFilters(
88 this.source.filter(params),
89 this.event.filter ?? {},
90 options.filter ?? {}
91 ),
92 },
93 source: {
94 version: "2",
95 key,
96 channel: this.source.channel,
97 params,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…