Sanity Library Reference Docs
    Preparing search index...

    What a generated Sanity Function calls: one verb per function kind, each taking the platform event.

    interface Runtime {
        engine: Engine;
        drain(
            event: { data: { _id: string } },
            options?: { effect: string },
        ): Promise<void>;
        heartbeat(): Promise<void>;
        start(
            event: { data: CandidateDocument & { _id: string } },
            options?: { definition: string },
        ): Promise<void>;
    }
    Index

    Properties

    Methods

    Properties

    engine: Engine

    An engine for a function of your own, with the effects registry as its handlers. Its drainEffects fails on a pending effect the registry lacks unless names leaves that effect out.

    Methods

    • Run the pending effects this drain owns on the instance the event names: a drain function's event, whose projection carries the instance _id. Without options, the drain owns every 'function'-hosted effect that declares no timeout or memory. With options.effect, it owns that one effect, which must declare one of them. Throws when an effect failed or was settled elsewhere during the run, so the platform records the invocation as failed.

      Parameters

      • event: { data: { _id: string } }
      • Optionaloptions: { effect: string }

      Returns Promise<void>

    • Re-queue the deployment's 'function'-hosted effects no drain picked up within five minutes of being queued, on any instance in the partition that holds one, releasing every expired claim on those instances, and tick every in-flight instance of its 'function'-hosted workflows and no other. Runs no effect handler. Each step works on at most 30 instances per call, and later calls reach the rest. Both steps run even when one fails; the call throws afterwards when any instance failed. On an instance it re-queues, a stale entry of an effect hosted elsewhere is re-queued too, and no generated drain runs it.

      Returns Promise<void>

    • Start the autonomous definitions applicable to the document a start watcher's event carries. Without options, the definitions whose start depends on no update; with options.definition, that one definition, which must have a start watcher of its own. Each start receives the document as its input-sourced subject, referenced in the dataset the event came from. Throws a ContractViolationError when the CreateRuntimeOptions.context given to createRuntime lacks clientOptions.projectId or clientOptions.dataset.

      Each start is keyed on the definition, the event's dataset, the document _id and its _rev, so calling start again with the same write, in sequence or concurrently, starts no second instance. Throws a ContractViolationError when the document has no _rev.

      Parameters

      • event: { data: CandidateDocument & { _id: string } }
      • Optionaloptions: { definition: string }

      Returns Promise<void>