obeli-sk-utils 0.41.4

Internal package of obelisk
Documentation
package obelisk:webhook@6.0.0;

@since(version = 5.0.0)
interface webhook-support {
    use obelisk:types/time@5.0.0.{schedule-at, datetime};
    use obelisk:types/execution@5.0.0.{execution-id, function, schedule-json-error, execution-failure-kind};

    /// Error variants that may occur when calling `get-status`.
    @since(version = 5.0.0)
    variant get-status-error {
        /// Cannot parse the execution ID.
        execution-id-parsing-error(string),
        /// The execution was not found.
        not-found,
    }

    /// Error variants that may occur when calling `get`.
    @since(version = 5.0.0)
    variant get-error {
        /// Cannot parse the execution ID.
        execution-id-parsing-error(string),
        /// The execution was not found.
        not-found,
    }

    /// Error variants that may occur when calling `try-get`.
    @since(version = 5.0.0)
    variant try-get-error {
        /// Cannot parse the execution ID.
        execution-id-parsing-error(string),
        /// The execution was not found.
        not-found,
        /// The execution has not finished yet.
        not-finished-yet,
    }

    /// The status of an execution, including cancellation.
    @since(version = 6.0.0)
    variant execution-status {
        /// Execution is scheduled to run at a specific time.
        pending-at(datetime),
        /// Execution is currently being processed.
        locked,
        /// Execution is currently paused.
        paused,
        /// Execution is waiting for child executions to complete (workflows only).
        blocked-by-join-set,
        /// Cancellation has been requested; the execution is being torn down.
        cancelling,
        /// Execution has finished.
        finished(execution-status-finished),
    }

    /// The finished status of an execution.
    @since(version = 6.0.0)
    variant execution-status-finished {
        /// Execution has finished with a successful result.
        ok,
        /// Execution has finished with an error result (user-level error).
        err,
        /// Execution has terminated due to an execution failure (system-level error).
        execution-failure(execution-failure-kind),
    }

    /// Generate a new top-level execution ID.
    @since(version = 5.0.0)
    execution-id-generate: func() -> execution-id;

    /// Get the execution ID of the current webhook handler invocation.
    /// Returns the ID assigned to this webhook execution by the engine.
    @since(version = 5.2.0)
    execution-id-current: func() -> execution-id;


    /// Call a function and wait for the result.
    /// Creates a child execution, waits for it to complete, and returns the result.
    /// Parameters are serialized as a JSON array.
    /// Returns Ok(Some(json)) for successful result with value,
    /// Ok(None) for successful result with no value,
    /// Err(Some(json)) for error result with value,
    /// Err(None) for error result with no value.
    @since(version = 5.0.0)
    call-json: func(function: function, params: string) -> result<result<option<string>, option<string>>, schedule-json-error>;

    /// Schedule a new top-level execution with its parameters serialized as JSON array.
    /// Use the execution ID returned by `execution-id-generate`.
    @since(version = 5.0.0)
    schedule-json: func(execution-id: execution-id, schedule-at: schedule-at, function: function, params: string) -> result<_, schedule-json-error>;

    /// Get the current status of an execution.
    /// Reports the `cancelling` state for cancellable workflows.
    @since(version = 6.0.0)
    get-status: func(execution-id: execution-id) -> result<execution-status, get-status-error>;

    /// The kind of platform-level execution failure for a previously *processed*
    /// child response (via `call-json` / `get` / `try-get`), or `none` if it
    /// finished with an ok / business `err` result. Additive to the err value.
    /// Errors the same way as `get` for an unknown or unfinished execution.
    @since(version = 6.0.0)
    get-execution-failure-kind: func(execution-id: execution-id) -> result<option<execution-failure-kind>, get-error>;

    /// The execution ID of the last direct call (`call-json`), or `none` if there
    /// was none. Pair with `get-execution-failure-kind` to resolve its failure kind.
    @since(version = 6.0.0)
    last-direct-call-id: func() -> option<execution-id>;

    /// Get the result of an execution, blocking until it finishes.
    /// Returns Ok(Some(json)) for successful result with value,
    /// Ok(None) for successful result with no value,
    /// Err(Some(json)) for error result with value,
    /// Err(None) for error result with no value.
    /// Outer result indicates lookup success/failure.
    @since(version = 5.0.0)
    get: func(execution-id: execution-id) -> result<result<option<string>, option<string>>, get-error>;

    /// Try to get the result of an execution without blocking.
    /// Returns immediately if the execution has finished, or `not-finished-yet` error otherwise.
    /// Returns Ok(Some(json)) for successful result with value,
    /// Ok(None) for successful result with no value,
    /// Err(Some(json)) for error result with value,
    /// Err(None) for error result with no value.
    /// Outer result indicates lookup success/failure.
    @since(version = 5.0.0)
    try-get: func(execution-id: execution-id) -> result<result<option<string>, option<string>>, try-get-error>;
}

/// Backtrace-carrying variants of the event-persisting `webhook-support` functions.
/// Only interpreted runtimes (the JS runtime) supply a source-level `backtrace`;
/// native components import the plain `webhook-support` interface instead.
@since(version = 6.0.0)
interface webhook-support-backtrace {
    use obelisk:types/time@5.0.0.{schedule-at};
    use obelisk:types/execution@5.0.0.{execution-id, function, schedule-json-error};
    use obelisk:types/backtrace@5.0.0.{wasm-backtrace};

    /// See `webhook-support.call-json`.
    @since(version = 6.0.0)
    call-json: func(function: function, params: string, backtrace: option<wasm-backtrace>) -> result<result<option<string>, option<string>>, schedule-json-error>;

    /// See `webhook-support.schedule-json`.
    @since(version = 6.0.0)
    schedule-json: func(execution-id: execution-id, schedule-at: schedule-at, function: function, params: string, backtrace: option<wasm-backtrace>) -> result<_, schedule-json-error>;
}