Guest mode
Guest mode lets someone try Solid Memo before logging in, in a pod kept in their browser. After logging in with a real WebID, the guest can move that study into their own Pod. Everything else works the same for a guest: the deck library, studying, statistics, preferences and the data check. A guest's instance is made as any new one is, so it studies by FSRS-6 (srs.md).
A pod in the browser
localPod.ts serves each guest a
small Solid pod as a fetch, which the app's Solid adapters use as they
do a server. A router
(routedFetch.ts) sends each
request to the guest's pod or to the network, by URL, after the pod
fence and the write fence
(boundaries.md).
The diagram's source
graph LR
accTitle: Routing a guest's requests
accDescr: Requests pass the pod fence and the write fence; those to the guest pod's address go to the local pod in IndexedDB, and every other URL goes through the authenticated fetch.
UI --> UseCases --> Adapters["Solid adapters"]
Adapters --> PodFence[podFence] --> Fence[writeFence] --> Router[routedFetch]
Router -- "guest.solid-memo.invalid" --> LocalPod[localPod] --> Store[(IndexedDB)]
Router -- every other URL --> authFetch --> Pod[(the user's pod)]- Origin:
https://guest.solid-memo.invalid/(GUEST_ORIGINin domain/guest.ts). The reserved.invaliddomain never resolves: a guest URL slipping past the router fails instead of reaching anyone. - WebID:
…/profile/card#me, written when the guest starts (GuestPod.start). Its profile names the pod's root as itspim:storage.createInstancecreates the instance and its private type index as on any pod. - What the pod speaks: GET, HEAD, PUT, DELETE, and PATCH with SPARQL
INSERT DATA/DELETE DATA. It gives ETags, honorsIf-Match,If-None-Match: *andIf-None-Match: <etag>, keepsldp:containslistings, and marks the root as apim:Storage. It has no access control. Requests run one at a time, under a Web Lock shared by every tab. - Who may name it: only a guest's own instance. A deck whose
catalog is in the guest's pod names documents only there, and a deck
of any other instance that names one there can't be used
(
isDeckInPlacein domain/deckAddress.ts,deckGone). A read as no one never goes to the guest's pod. - Storage: the
ResourceStoreport. In the browser it's indexedDbResourceStore.ts, so the study survives the login redirect. Without IndexedDB, an in-memory store keeps it for the current page only. It's the one place pod data lives in browser storage, and only a guest's.
restoreSession prefers a real session. Without one, it returns a
guest's session ({ webId: GUEST_WEBID, guest: true }) whenever a
guest pod exists in this browser.
From a link
A link to a library deck, #/try?deck=…, is for anyone and doesn't
wait for "Try it without logging in": without a session, the app starts
a guest's study as that button does and opens the deck there
(routing.md). So does a link to
a release published outside the library, #/try?url=…, which opens it
to add (routing.md). A browser with a
guest pod goes on with it (restoreSession returns the guest's
session), and the deck opens in the guest's instance. A logged-in
user's opens it in their own. A guest's study that can't start leaves the
landing page, with the reason.
What comes from outside
When the study is kept, every address that names the guest's pod must be one of the study's own, which the move gives a new place (Keeping the study). So data from outside never brings one in, for a guest and a logged-in user alike:
- a release, from the library or a link,
is refused when it's at the guest's pod or links to it by an
address in it, such as a card's picture or what it's about
(
releaseLinksGuestPod); - so is a release made a draft, from a file or as
a next version. So is a next version whose series or publisher, as
the documents they're described in say, links to it, such as by the
earlier versions the series lists (
dcat:hasVersion); - so is a deck file with such an
address (
deckFileLinksGuestPod). The deck's, its cards' and their documents' own addresses may name it: the import gives them new ones.
Text the reader reads, such as card text and notes or what changed in
a release, may name any address. So may the fragment id of a card or a
wrong option, and a review state's reference to it. Such an id is no
address but the part after the # of the deck's own document, so it's
copied as it is, and keeping the study doesn't refuse it.
The address of a release, and of a chapter in it, is the address of the release a deck was taken from. It's read as one whole address, and only one at the guest's pod counts: its path, query or fragment may spell anything, and a deck taken from it can be kept, as in a move into a new instance.
Keeping the study
The diagram's source
stateDiagram-v2
accTitle: Keeping a guest's study
accDescr: A guest logs in and is offered to move the study into their Pod, where it is added or moved, and a failure leaves the study untouched.
[*] --> Guest: Try it without logging in
Guest --> Login: Keep my study — log in
Login --> Guest: Back to my study
Login --> Offer: logged in (guest pod still here)
Offer --> Adding: Move it into my Pod (the user has an instance)
Offer --> Moving: Move it into my Pod (the user has none)
Offer --> [*]: Discard it / Not now
Adding --> Added: every deck in, the guest's study unchanged meanwhile
Adding --> Offer: failed — the decks added stay, whole — study untouched
Moving --> Moved: registered in the user's type index
Moving --> Offer: failed — copy removed, study untouched
Guest --> [*]: DiscardThe guest pod's presence marks a study to keep, so nothing has to
survive the redirect. After any login or
restored session,
GuestStudyOffer asks findGuestStudy and makes the offer while a
guest pod exists. Move it into my Pod first lists the user's
instances. With at least one, the study is added to the one the user
chooses (Adding to an instance). With none,
or when they can't be listed, it moves into a new instance
(As a new instance). Logging in keeps the guest
pod for later.
Adding to an instance
mergeGuestStudy adds the guest's decks, deck by deck, to the instance
the user chose (the first listed, unless they pick another). The form
lists the guest's decks (planGuestMerge), each checked; an unchecked
deck stays with the guest's study. At least one deck must stay
checked, unless the study has none.
A guest's deck from the same library release as one
of the instance's (the same prov:wasDerivedFrom) says so. It's added
beside that deck with its own progress, never merged card by card, and
the user may uncheck it. The form says the instance keeps its own
preferences: the guest's aren't carried over. Nor is the guest's
digest, which is this browser's. Drafts the guest wrote in the
Studio are copied too. When there are any, the
form says how many and the names they're copied under (step
drafts).
It runs these steps:
read: list the guest's instance, noting each document's version before any is read. A study that holds more than 20,000 resources, folders more than 8 levels deep, or an answer log of
MAX_LOG_MONTHSmonths is refused (guestStudyTooLarge). Answers waiting to be logged go to the guest's log first, and the write fence keeps the guest's instance read-only meanwhile. The whole instance, answer log included, is checked against the shapes. Nothing is added from a study that doesn't fully conform (guestStudyInvalid), or that a newer app version wrote (guestStudyTooNew). Such a study has a subject in a newer format, or a document that uses a term of the vocabulary this version doesn't know (namesLaterTerm) where only a term goes. That's a property, a subject's class, or the value of a property whose values are concepts (rdfs:range skos:Concept, such assm:scheduler). An IRI of the vocabulary as the value of any other property, such as a card'sdcterms:subject, is a resource like any other and doesn't count. Adding writes what this version reads of each deck, so what a later one said beside it would be left behind, and go with the guest's study. A draft's documents aren't asked: a draft is copied with what this version reads of it, which keeps statements in terms it doesn't know, as a draft made from a release keeps what the release states. Nor from a study with deck groups when a newer version wrote the instance's arrangement (deckTreeTooNew), refused before any deck is written. Nor when the kept decks, but any an earlier run added, would give the instance more decks than its catalog is read with (guestMergeTooManyDecks, data-model.md). Nor when the guest's groups would give its arrangement more groups than it's read with (catalogFull). Nor when a draft's copy, under the longest name it may take in the instance, would hold an IRI longer than a term may be (draftCopyTooLong, which names the draft). A draft's IRIs grow with the instance's address, which is longer than the guest's. Nor when a draft names an IRI its copy couldn't be written with as it is (draftCopyUnwritable, which names the draft too). Nor when the drafts would give the instance's drafts more documents than are read together (draftTooManyDocuments). A draft an earlier run copied, unchanged since, isn't asked again; with no draft left to copy, the instance's drafts aren't read.decks: each kept deck becomes a new deck of the instance, in the guest's order (data-model.md):
- a new id (
deck-<uuid>), with its cards and reviews documents named after it in the instance'sdecks/andreviews/. The rest of its entry is the guest's: title, description, authors, license, topics, keywords, direction, pace, card language (sm:deckCardLanguage), picture hosts (sm:deckPictureHost) and creation time. So are the release it came from (prov:wasDerivedFrom) and, for a course's deck, itsschema:Coursetype and completed chapters (sm:completedChapter). An author's name comes from a release, and its agent node fit under the guest's short catalog address. An author whose node in the instance's catalog could be longer than a term may be, with the hash and count a node may take after its name, is left out, as a card that doesn't fit is (authorFitsDeck); - its cards keep their fragment ids, distractors and creation times, written in this app's format, the document saying it's part of the deck. Its review states keep their SM-2 fields and snapshots, each naming its card, direction and scheduler; its FSRS-6 states come as they are;
- a card's id, or a distractor's, comes from a release and may fit
under the guest's short address but not under the new deck's. A
card whose IRI there would be longer than a term may be is left
out, with its review states and its answers: it could be neither
written nor studied there (
cardFitsDeck). A review state whose name after its card (#<id>@back-to-front@fsrs6the longest) would be too long is written at a short subject of its own, which names its card, and the card is kept. Such a distractor is left out, not the card (movedCard). A course still asks the card with its release's options, which it reads from the release; - the cards document, then the reviews document, is created with
one PUT only where nothing is, then the deck's catalog entry, with
If-Match, read and added again on 412 a few times at most. Until the entry is written, nothing names the documents. A failure before the entry deletes the documents it wrote, and any whose write's answer was lost, never one the pod refused to create. If one can't be deleted, the failure says where it is. If the catalog can't be read to tell whether the entry was written, they stay and the failure says to look for the deck first. If only the entry's answer was lost, the deck is whole. A deck with no cards, or no review states, has no such document yet; - then its answers: each of the deck's answers in the guest's log is
added to the instance's log for its month, insert-only, unread
(
appendAll, one PATCH per month, more where one would pass 64 KiB). Its deck, card and chosen wrong option are named in the new deck's documents, by the same fragment ids. A chosen wrong option whose IRI would be too long there, or whose id is longer than 256 characters, is left out, not the answer. Its grade, intervals and response times stay as given. Its id is the guest's followed by the new deck's (answer-<time>-<random>-deck-<uuid>). Answers of a deck the guest removed, or left out, aren't added, nor those of a card left out.
No address in a deck's entry, cards or review states may name the guest's pod, in any spelling of its origin (
guestDeckUrlsLeft, which names the deck, so it can be left out). Text the reader reads, such as titles, card text and notes, may name any address and is copied as it is, as is a fragment id, which is no address. The address of a release or a chapter (a deck's source, a card's release and the chapters completed) counts only as a whole, whatever it spells inside. Nothing is registered: the instance's catalog and folders hold the added decks.- a new id (
arrange: each of the guest's deck groups becomes a new group (
#group-<uuid>) with its name, holding the added decks and new groups it held, an empty one empty. They go, in the guest's order, after the instance's own decks and groups, at the top level. It's onegraftedit: one PATCH withIf-Match, applied again on 412, which numbers the top level anew. With no group, nothing is written, and the added decks are listed after the instance's.drafts: each draft the guest's catalog links is copied to the instance (
copyReleaseDraft): read whole, every subject moved todrafts/<name>/v<N>/in the instance, at its version, under its name. When the instance has a draft of that name and version, it takes the next free name (<name>-2, …). It's written as a new draft is (data-model.md). A draft whose link can't be written is taken back, and none of the instance's is written over. A copy that would still link to the guest's pod by an IRI isn't written (guestUrlsLeft); its text may name any address.verify: the guest's instance must still list the same resources, each at the version noted in read (
guestStudyChanged).tidy: delete the guest's instance as any instance is deleted (data-model.md), and the whole guest pod once no instance is left. A failed delete only means
tidied: false.
A failure leaves the instance valid and the guest's study as it was.
Every deck reported added (added) is whole: documents,
entry and, unless the failure was in adding them, answers. The only
other writes are the groups, after arrange, the drafts reported
copied (copied), each whole, and any unnamed deck document whose
deletion failed. The user is told which decks and drafts (under their
names there) are in the instance. A text or address too long that
stops the merge once part of the study is added names the deck
(guestDeckTooLong) or the draft (draftCopyTooLong,
draftCopyUnwritable), so it can be left out or deleted.
Trying again adds what isn't there yet. As each deck is added, and
before each group is, this browser's update journal notes
(GuestMergeNote) the new deck or group and a SHA-256 digest of what
it was made from:
- for a deck, the guest's catalog entry and the versions of the guest's documents it was read at;
- for a group, the whole arrangement of the guest's groups around the added decks;
- for a draft, the versions of its documents.
On the next run:
- A deck whose entry and documents are as noted gets only its answers again, a no-op.
- When the arrangement is as noted, each group is made under its earlier URL, so a graft already made stays.
- A deck the guest changed since, in its entry or documents, is added anew beside the earlier one (which the user may remove). So is a deck the instance no longer has, and any deck without a note (the journal is best effort). Its answers become new entries whose ids name the new deck, so no log entry names two decks.
- Groups arranged otherwise than noted (a deck added anew among them) are made anew, holding the added decks; the earlier groups stay, without them.
- A noted draft at the same versions, whose copy the instance still links, isn't copied again; otherwise it's copied anew, under the next free name.
A digest keeps a note small, however much a deck's entry holds. A note an earlier version kept, holding what the deck or group was made from whole, is rewritten as its digest as the app starts, before anyone signs in, so a run it noted is still found.
A merge that deletes the guest's study forgets the notes. So does discarding the guest's study, and looking for one when the guest's pod is gone. Looking for a guest's study also forgets the notes of a guest's instance no longer in the pod, and a merge first forgets those of a deck, group or draft the study no longer holds. A move's entry is left as it is.
The journal keeps no entry, key and value together, longer than 65,536 characters. One longer isn't written, and the source's earlier entry goes. An entry that long that an earlier version kept, and that isn't a note it can rewrite short, is dropped as the app starts.
As a new instance
transferGuestStudy copies the guest's instance into a container the
user chooses (by default <storage>solid-memo/main/, where a first
instance goes). It runs these steps:
- stage: refuse (
typeIndexNoStorage) when the study couldn't be registered: no type index of the chosen kind, and no storage the user's WebID leads to where one could be made (data-model.md). List the guest's instance, without the digest (this browser's), refused past the same bounds as above (guestStudyTooLarge). Check the target is free, then create it. Answers waiting to be logged go to the guest's log first. Refuse, before anything is written, a deck with an author whose agent node would be longer than a term may be under the target (guestDeckTooLong), or a draft whose copy would hold such an IRI (draftCopyTooLong). Each names the deck or draft. Deleting a copy that failed half-way walks it within the same bounds. - copy: copy each resource with every IRI under the guest's
instance moved under the target, and the guest's WebID renamed to the
user's (
ContainerMove.renames). A copy of a card whose IRI would be longer than a term may be under the target fails, as below. Added to an instance instead, such a card is left out. - adopt: name the catalog's publisher as the user's profile names
them. No Turtle document of the copy may still name an IRI at the
origin of
GUEST_ORIGIN, in any spelling. The failure names the guest's deck the document is of (guestDeckCopyUrlsLeft), so it can be removed from the guest's study: the deck's cards or reviews document, or the catalog whose entry of it links there. Else it names the document (guestUrlsLeft). Literals aren't looked at, their text or their datatypes: the copy moves only the IRIs of subjects, predicates, objects and graphs, and text such as a card's may name any address. - validate: the copy must fully conform to the shapes
(
movedCopyInvalid). - verify: the guest's instance must be unchanged since it was copied. The write fence keeps it read-only meanwhile, in the site's other open tabs too.
- register:
attachInstancein the type index the user chose. From here on the study is theirs. - tidy: delete as the merge's tidy does. Nothing more is
registered: the instance's
sm:Instanceregistration leads to the rest of its data (data-model.md).
A failure before register deletes the copy, whole, and leaves the guest's study as it was. The target's container, created where nothing was and named by nothing before register, holds only Solid Memo's copies. This browser's update journal notes the run:
- A copy a closed tab left behind is offered for removal, with the
offer to keep the study, the next time the user is logged in
(
InterruptedMoveContainer), and removed whole, unless one of the two cases below holds. - A tab can close after register was made but before its answer came. The note then names one of the user's instances, so the folder isn't offered or removed: the note is dropped, as the move ended.
- A folder that holds anything the move didn't write, another app's file or the user's study, is no longer only the copy. It isn't offered or removed either, and the note is dropped.
- A move retried first, at the copy's place, fails before writing anything and leaves the note.
- A copy another tab's move is still writing isn't offered or removed.
The copy inherits the user's pod's default access control, like a new instance; a guest's instance has none.
While a move runs, the site's other open tabs (the web app's and the
Studio's, which share one origin) hold the guest's instance and its
copy: a write there fails with the moving tab's message. The moving tab
holds a Web Lock named after its journal entry until the move ends,
failed or not, or the tab closes or crashes. Other tabs read the
entries on opening, then follow storage events, holding what an
entry names only while its lock is held. An entry a failed move keeps,
one a closed tab left, or one noting a deck added to an instance fences
nothing. A browser without Web Locks fences no other tab; verify
catches what it misses.