Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0006-anyfs-documents FR-005
Where the documents of a collection are, as code: a layout is a pair of functions between a typed key and a path below the collection, and the second is the inverse of the first, so that a listing can name the key of every object it finds and name the objects that are none of the collection's. The keys are made by smart constructors: an identifier is a safe name of one segment, a date is a day of the calendar. Three layouts are here (by identifier, by identifier below a shard of its first characters, by day); another is a value of the same type.
import { byId, parseDocId, parseExtension } from"./layout.ts";
constext=parseExtension(".json");
constid=parseDocId("olympia");
if (ext.kind ==="ok"&& id.kind ==="ok") byId(ext.value).path(id.value); // ok "olympia.json"
The name of one document: one segment of letters, digits and . _ ~ @ + = -, beginning with a letter or digit, of at most 128 characters. Made only by parseDocId.
The layout with the files below a folder of the first width characters of the identifier (one to four): <shard>/<id><extension>, so that no folder holds all of them.