Solid Accord
    Preparing search index...

    The object an app uses to save its work and connect the user's Pod, made by createClient. An app has one. It keeps the current work in this browser, and in the Pod once one is connected.

    interface Client {
        onStateChange: ((state: ClientState) => void) | null;
        connectPod(webId: string, work?: Work | null): Promise<void>;
        disconnectPod(): Promise<void>;
        resumeSession(
            restoreWork?: (work: Work | null) => void | Promise<void>,
        ): Promise<void>;
        save(work: Work): Promise<SaveResult>;
    }
    Index
    onStateChange: ((state: ClientState) => void) | null

    Called with the whole state each time it changes, so the app can show it. If it throws, that's logged, and the method that changed the state goes on.

    • Connects the user's Pod, from their WebID: it keeps work, if given, in this browser as the current work, then logs in with the Solid OIDC issuer named in their profile, so the page leaves for the identity provider and comes back to the identity's redirectPath (/ unless it names another), where resumeSession finishes the login and writes the current work to the Pod.

      The state's pod is connecting meanwhile, and work is saved-locally once the work is kept. If the login can't start, the page stays and pod is failed, saying why: the codes invalid-web-id, profile-unreadable and no-oidc-issuer say it's worth asking for the WebID again. It never throws.

      Parameters

      • webId: string
      • Optionalwork: Work | null

      Returns Promise<void>

    • Disconnects the Pod: it ends the session in this app, forgets the WebID, and forgets the current work, removing it from this browser. The next save starts a new work, saved in the browser until a Pod is connected. The work already in the Pod stays there, and the user stays logged in at their provider. The state's pod is then not-connected, and its work is none.

      It never throws. If the browser's storage won't let it forget all of that, the failure is logged, and it tries every step even so, forgetting the WebID first, so the next save doesn't go to this Pod unless that step was the one that failed.

      Returns Promise<void>

    • Call it on every page load, after setting onStateChange. It reads the current work from this browser and hands it to restoreWork, to put back in the editor, straight away; then it restores an earlier session, so later saves need no login, and if the page is returning from logging in, it finishes connecting and writes the current work to the Pod. Each step is reported to onStateChange, the first of them before restoreWork is called. It never throws: a failure is in the state.

      Parameters

      • OptionalrestoreWork: (work: Work | null) => void | Promise<void>

        called once, with the current work or null if there isn't one, before anything else happens. If it returns a promise, that's waited for. If it throws or rejects, that's logged, and the rest goes on, so a login still finishes and the work, still kept in this browser, is still written to the Pod.

      Returns Promise<void>

    • Saves the work as the current work: in this browser, and then, if a Pod is connected, to the Pod. The first save starts a new work; every save after it, even with a different title, replaces it, until disconnectPod.

      If the session with the Pod has lapsed, it logs in again with the connected WebID, without asking: the page leaves, with the work kept in the browser, and resumeSession writes it to the Pod on the page load that follows.

      Each step is reported to onStateChange, as the state's work, as it happens.

      Parameters

      Returns Promise<SaveResult>

      where the save ended up. It never throws: a failure is a failed status.