UNPKG

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.

66 lines (64 loc) 2.5 kB
const require_consts = require('../helpers/consts.cjs'); const require_marker = require('../helpers/marker.cjs'); const require_InngestFunction = require('./InngestFunction.cjs'); //#region src/components/DeferredFunction.ts const idDenyRegex = /['\\\n\r]/; /** * EXPERIMENTAL: This API is not yet stable and may change in the future without * a major version bump. * * A defer (companion) function created via `createDefer(...)`. Real * `InngestFunction` at runtime, but with the trigger pinned to * `inngest/deferred.schedule` (see `getConfigTriggers`), `triggers` and * `onFailure` disallowed, and the schema carried as a typed instance * property so callers of `defer(id, { function, data })` can extract it. * * Identify a defer function at runtime via `isDeferredFunction(value)` from * `helpers/marker.ts`. Prefer that over `instanceof`, which fails across * duplicate SDK copies in the same process. * * @public */ var DeferredFunction = class extends require_InngestFunction.InngestFunction { schema; [require_marker.markerKey] = { kind: "deferredFunction" }; constructor(client, opts, handler, schema) { if (idDenyRegex.test(opts.id)) throw new Error(`invalid id "${opts.id}"; must match ${idDenyRegex.source}`); super(client, { ...opts, triggers: [] }, handler); this.schema = schema; } getConfigTriggers(fnId) { return [{ event: require_consts.internalEvents.DeferredSchedule, expression: `event.data._inngest.fn_slug == '${fnId}'` }]; } }; /** * EXPERIMENTAL: This API is not yet stable and may change in the future without * a major version bump. * * Create a typed defer function. One `createDefer` call = one Inngest * function. Returns a `DeferredFunction<TSchema>` so callers of `defer(id, * { function, data })` get the data type inferred from the schema. * * Mirrors `inngest.createFunction(opts, handler)`, with three differences: * the client is the first positional arg, `triggers` is not accepted (the * SDK emits an implicit `inngest/deferred.schedule` trigger), and `schema` * describes the payload that callers will send via `defer(id, { function, * data })`. * * Pass the result to `serve()` alongside regular functions so the SDK * registers it. */ function createDefer(client, options, handler) { const { schema, ...rest } = options; return new DeferredFunction(client, rest, handler, schema); } //#endregion exports.DeferredFunction = DeferredFunction; exports.createDefer = createDefer; //# sourceMappingURL=DeferredFunction.cjs.map