Function definePollingTrigger

  • Used to define a Connector Polling Trigger.

    Type Parameters

    Returns (<Name, InputParamsSchema, PayloadSchema>(definitionInput) => PollingTriggerDefinition<Name, Cred, State, InputParamsSchema, PayloadSchema>)

      • <Name, InputParamsSchema, PayloadSchema>(definitionInput): PollingTriggerDefinition<Name, Cred, State, InputParamsSchema, PayloadSchema>
      • Type Parameters

        • Name extends string

        • InputParamsSchema extends TObject<TProperties>

        • PayloadSchema extends AnyTriggerPayloadSchemaShape | TriggerPayloadSchemaFn<Cred, InputParamsSchema>

        Parameters

        • definitionInput: PollingTriggerDefinitionInput<Name, Cred, State, InputParamsSchema, PayloadSchema>

        Returns PollingTriggerDefinition<Name, Cred, State, InputParamsSchema, PayloadSchema>

    See

    Triggers

    Example

    import { definePollingTrigger } from "@rollout/framework";
    import { MyAppCredential } from "./auth";
    import { inputParamsSchema } from "./input";
    import { payloadSchema } from "./payload";

    // State represents the value we want to store in between pollings.
    // Here, we will be storing Set of string IDs.
    type State = Set<string>;

    export const trigger = definePollingTrigger<MyAppCredential, State>()({
    name: "My Polling Trigger",
    inputParamsSchema,
    payloadSchema,
    async poll({ credential, prevState }) {
    const allItems = await getAllItems({ credential, order: "createdAt-asc" });
    const newState = new Set(allItems.map((c) => c.id));
    const newItemIds = diffIdSet(newState, prevState);
    const events = allItems.filter((c) => newItemIds.has(c.id))

    return { newState, events };
    },
    });