CAPABILITIESconstconst CAPABILITIES: readonly ["read", "write", "list", "stat", "delete"]The capabilities of the store: no cas, because Drive keeps no condition on a write.
The store over a folder of Google Drive. Drive addresses files by identifier, keeps a folder as a file of its own and allows many files of one name in one folder, so the store resolves a path to identifiers one folder at a time by asking for a name in a parent, and where a name is held more than once it means the oldest (by creation time, then by identifier), which every writer follows. A write that expects no object makes the file and then asks for the name again: where an older file is there it removes its own and says the object was there, so that of several writers exactly one wins; the folders it makes on the way are settled the same way. Drive keeps no condition on a write, so the store has no cas and says so in its type: a revision cannot be expected here, and a store that pretended to would lose a change.
The revision of an object is sha256: and the digest of its bytes, the same as in every other store: Drive keeps sha256Checksum for a blob, and where it does not the store reads the bytes.
Limits, said once: an object is whole and at most maxBytes (5 MiB, the most one multipart upload takes; a resumable upload is a later capability); a path costs a request for each of its folders, since identifiers are not kept between operations; a listing walks every folder below the prefix; a Google document, sheet, slide or shortcut is not an object; two files of one name made by another client are one object, the oldest, and the other is left alone; a delete moves to the trash unless the store is told to remove for good.
import { openDriveStore, staticToken } from "./store.ts";
// const opened = await openDriveStore({ place, token: staticToken(process.env.TOKEN ?? "") });
// opened.kind === "ok" && opened.value.capabilities.has("cas"); // falseCAPABILITIESconstconst CAPABILITIES: readonly ["read", "write", "list", "stat", "delete"]The capabilities of the store: no cas, because Drive keeps no condition on a write.
openDriveStorefunctionfunction openDriveStore(options: DriveOptions): Promise<Result<DriveStore, string>>A store on a folder of Drive, or why there is none. The folder is asked once, so that a token that is not accepted, or a folder that is not there, is found here.
DriveOptionstypeno test imports ittype DriveOptions = {
/** The folder: `parsePlace("gdrive://FOLDER-ID")`. */
readonly place: DrivePlace;
readonly … (1032 characters)type DriveOptions = {
/** The folder: `parsePlace("gdrive://FOLDER-ID")`. */
readonly place: DrivePlace;
readonly token: TokenSource;
/** Where the API listens: `https://www.googleapis.com` where it is left out. */
readonly endpoint?: string;
/** The most bytes an object may have: 5 MiB where it is left out, and never more (the most one multipart upload takes). */
readonly maxBytes?: number;
/** What a delete does: move to the trash (the default) or remove for good. */
readonly deletion?: "trash" | "delete";
readonly transport?: Transport;
/** How long a request may take: 30 s where it is left out. */
readonly timeoutMs?: number;
/** How many files a listing asks the bytes of at once: 8 where it is left out. */
readonly listConcurrency?: number;
/** The most entries a listing walks: 100000 where it is left out. */
readonly maxEntries?: number;
/** The most requests a listing makes: 5000 where it is left out. */
readonly maxRequests?: number;
readonly consistency?: Consistency;
};What a store is made with.
DrivePlacetypeno test imports ittype DrivePlace = Extract<Place, { readonly kind: "gdrive" }>;The place of a store on Google Drive.
DriveStoretypeno test imports ittype DriveStore = Store<(typeof CAPABILITIES)[number]>;The store.