Need to define the class like EventTrigger
This commit is contained in:
@@ -40,10 +40,16 @@ export const ScheduledTriggerMetadataSchema = z.object({
|
||||
schedule: ScheduleMetadataSchema,
|
||||
});
|
||||
|
||||
export const AssetTriggerMetadataSchema = z.object({
|
||||
type: z.literal("modular"),
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
export const TriggerMetadataSchema = z.discriminatedUnion("type", [
|
||||
DynamicTriggerMetadataSchema,
|
||||
StaticTriggerMetadataSchema,
|
||||
ScheduledTriggerMetadataSchema,
|
||||
AssetTriggerMetadataSchema,
|
||||
]);
|
||||
|
||||
export type TriggerMetadata = z.infer<typeof TriggerMetadataSchema>;
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
import { RequestFilterSchema } from "@trigger.dev/core";
|
||||
import {
|
||||
DisplayPropertiesSchema,
|
||||
EventFilter,
|
||||
EventFilterSchema,
|
||||
RequestFilterSchema,
|
||||
} from "@trigger.dev/core";
|
||||
import { z } from "zod";
|
||||
import { TriggerClient } from "../triggerClient";
|
||||
import { EventSpecification, EventSpecificationExampleSchema, Trigger } from "../types";
|
||||
import { Job } from "../job";
|
||||
|
||||
const HttpTriggerOptionsSchema = z.object({
|
||||
id: z.string(),
|
||||
title: z.string().optional(),
|
||||
icon: z.string().optional(),
|
||||
properties: DisplayPropertiesSchema.optional(),
|
||||
verify: z
|
||||
.object({
|
||||
filter: RequestFilterSchema.optional(),
|
||||
requestFilter: RequestFilterSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
payload: z
|
||||
.object({
|
||||
requestFilter: RequestFilterSchema.optional(),
|
||||
schema: z.any().optional(),
|
||||
examples: z.array(EventSpecificationExampleSchema).optional(),
|
||||
filter: EventFilterSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
@@ -17,11 +35,43 @@ type HttpTriggerOptions = z.infer<typeof HttpTriggerOptionsSchema> & {
|
||||
};
|
||||
};
|
||||
|
||||
export class HttpTrigger {
|
||||
export class HttpTrigger<TEventSpecification extends EventSpecification<TEvent>, TEvent = any>
|
||||
implements Trigger<TEventSpecification>
|
||||
{
|
||||
constructor(
|
||||
private readonly client: TriggerClient,
|
||||
options: HttpTriggerOptions
|
||||
private readonly options: HttpTriggerOptions
|
||||
) {}
|
||||
|
||||
get event() {
|
||||
return {
|
||||
name: this.options.id,
|
||||
title: this.options.title ?? "http",
|
||||
source: "http",
|
||||
icon: this.options.icon ?? "world-www",
|
||||
properties: this.options.properties,
|
||||
schema: this.options.payload?.schema,
|
||||
examples: this.options.payload?.examples,
|
||||
filter: this.options.payload?.filter,
|
||||
parsePayload: (payload: unknown) => payload as TEvent,
|
||||
runProperties: (payload: TEvent) => [],
|
||||
};
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
type: "modular" as const,
|
||||
id: this.options.id,
|
||||
};
|
||||
}
|
||||
|
||||
attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
get preprocessRuns() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const trigger = new HttpTrigger(
|
||||
|
||||
Reference in New Issue
Block a user