inngest
Version:
Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.
141 lines (139 loc) • 5.67 kB
text/typescript
import { StandardSchemaV1 } from "@standard-schema/spec";
//#region src/components/triggers/triggers.d.ts
/**
* Create a cron trigger for scheduled function execution.
*
* @param schedule - Cron expression (e.g., "0 0 * * *" for daily at midnight)
* @returns Cron trigger
*/
declare function cron<T extends string>(schedule: T): {
cron: T;
};
/**
* Args for the `EventType.create` method
*/
type EventCreateArgs<TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined> = TSchema extends undefined ? [data?: Record<string, unknown>, options?: {
id?: string;
ts?: number;
v?: string;
}] : [data: ExtractSchemaData<TSchema>, options?: {
id?: string;
ts?: number;
v?: string;
}];
/**
* Extract the input type from a StandardSchemaV1.
*/
type ExtractSchemaData<TData> = TData extends StandardSchemaV1<infer TData> ? TData : undefined;
/**
* An event that has been created but not validated.
* @template TData - The input data type of the event (i.e. before validation)
* @template TOutputData - The output data type of the event (i.e. after validation)
*/
type UnvalidatedCreatedEvent<TName extends string, TData> = ValidatedCreatedEvent<TName, TData> & {
validate: () => Promise<void>;
};
/**
* An event that has been validated.
* @template TData - The data type of the event.
*/
type ValidatedCreatedEvent<TName extends string, TData> = {
data: TData;
name: TName;
id?: string;
ts?: number;
v?: string;
};
type EventTypeWithAnySchema<TName extends string> = EventType<TName, any>;
/**
* Represents a typed event definition that can be used both as a trigger
* and for creating events with validation.
*
* @template TName - The event name (e.g., "user.created")
* @template TSchema - Optional StandardSchema for type-safe event data
*/
declare class EventType<TName extends string, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined> {
/**
* The event name. This is the same as the `name` property, but is necessary
* to make the event type compatible with other features (e.g. event
* triggers).
*/
readonly event: TName;
readonly name: TName;
schema: TSchema;
version?: string;
constructor({
name,
schema,
version
}: {
name: TName;
schema: TSchema;
version?: string;
});
/**
* Creates an event to send.
*
* The returned event object includes a `validate()` method that can be called
* to validate the event data against the schema (if one was provided). The
* `validate()` method returns a new event object with the validated data,
* including any transforms defined in the schema.
*
* Validation is not performed within this method because validation may be async.
*
* @param data - Event data (required if schema is defined, optional otherwise)
* @param options - Optional event options including id, timestamp, and version
*/
create(...args: EventCreateArgs<TSchema>): UnvalidatedCreatedEvent<TName, ExtractSchemaData<TSchema>>;
}
/**
* This type's only purpose is to clearly highlight static type error messages
* in our codebase. To end users, it's exactly the same as a normal string.
*/
type StaticTypeError<TMessage extends string> = TMessage;
/**
* Ensure that users don't use transforms in their schemas, since we don't
* support transforms.
*/
type AssertNoTransform<TSchema extends StandardSchemaV1 | undefined> = TSchema extends undefined ? undefined : TSchema extends StandardSchemaV1<infer TInput, infer TOutput> ? [TInput] extends [TOutput] ? TSchema : StaticTypeError<"Transforms not supported: schema input/output types must match"> : StaticTypeError<"Transforms not supported: schema input/output types must match">;
/**
* Create an event type definition that can be used as a trigger and for
* creating events.
*
* This is the primary way to define typed events in Inngest. It creates an
* EventType instance that provides type safety and optional runtime validation.
*
* @param name - The event name (e.g., "user.created")
* @param options - Optional options for the event type
* @param options.schema - Optional StandardSchema for type-safe event data validation
* @param options.version - Optional version of the event
* @returns EventType instance that can be used as a trigger or for creating events
*/
declare function eventType<TName extends string, TSchema extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined>(name: TName, {
schema,
version
}?: {
schema?: AssertNoTransform<TSchema>;
version?: string;
}): EventType<TName, TSchema>;
/**
* Create a type-only schema that provides TypeScript types without runtime
* validation. Returns a hardcoded StandardSchemaV1 whose `validate` is a
* passthrough, so invalid data will not be rejected at runtime. Use this when
* you want event type safety without pulling in a validation library like Zod.
*/
declare function staticSchema<TSchema extends Record<string, unknown>>(): StandardSchemaV1<TSchema>;
/**
* Create an invoke trigger for function-to-function calls.
*
* This creates a trigger that allows your function to be invoked directly by
* other functions using `step.invoke()`. The schema defines the expected data
* structure for invocations.
*
* @param schema - StandardSchema defining the invoke payload structure
* @returns Invoke trigger
*/
declare function invoke<TData extends Record<string, unknown>>(schema: StandardSchemaV1<TData>): EventType<"inngest/function.invoked", StandardSchemaV1<TData, TData>>;
//#endregion
export { EventType, EventTypeWithAnySchema, cron, eventType, invoke, staticSchema };
//# sourceMappingURL=triggers.d.cts.map