• Register a Resource on graph keyed by key. The host application is responsible for scheduling fetch() calls; the engine merely carries the state.

    Type Parameters

    • T

      Resolved value type produced by the loader.

    Parameters

    • graph: Graph

      The engine instance to register the input against.

    • key: string

      Stable NodeId for the underlying input node.

    • options: ResourceOptions<T>

      Loader callback plus optional staleness-guard flag.

    Returns ResourceHandle<T>

    A ResourceHandle exposing the node and triggers.

    Internally this allocates a single InputNode initialised to { state: 'idle' } and returns an object that drives transitions on that input through one-shot commits. The transitions implemented are the ones drawn in the ResourceFleet sub-statechart: Idle → Loading → Loaded | Stale | Errored, plus Loaded → Stale (via ResourceHandle.invalidate) and the chart-named Loading | Loaded → Errored edges (via ResourceHandle.fail). Every transition lands as exactly one engine commit, advancing GraphTime by one tick — the engine has no other mutation API.

    const user = resource(graph, 'user:42', {
    loader: async () => fetchUser(42),
    })
    await user.fetch()
    graph.read(user.node) // { state: 'loaded', value: ..., ... }