parseItemfunctionfunction parseItem(json: unknown): Result<Item, string>An item from parsed JSON, or why it is not one.
The items Graph answers with, read strictly: a drive item has an id, a name, a size, an entity tag and a time, and is a file (with the hashes of its contents where Graph keeps them), a folder, or something that is neither (a package such as a OneNote notebook, a shortcut); a page of children has the items and, where there are more, the address of the next page. Everything is read from JSON that is checked, never cast, and a field of another type is a reason and not a guess.
import { parseItem } from "./items.ts";
const item = parseItem({ id: "1", name: "a.txt", size: 3, eTag: "\"{X},1\"", file: { hashes: { sha256Hash: "AB" } } });
item.kind === "ok" && item.value.kind; // "file"parseItemfunctionfunction parseItem(json: unknown): Result<Item, string>An item from parsed JSON, or why it is not one.
parsePagefunctionfunction parsePage(json: unknown): Result<Page, string>A page from parsed JSON, or why it is not one.
Itemtypeno test imports ittype Item =
| { readonly kind: "file"; readonly id: string; readonly name: string; readonly size: number; readonly eTag: string; readonly modified?: string; readonly sha256?: string }
| { readonly kind: "folder"; readonly id: string; readonly name: string }
| { readonly kind: "other"; readonly id: string; readonly name: string };What an item is.
Pagetypeno test imports ittype Page = { readonly items: readonly Item[]; readonly next?: string };A page of the children of a folder: its items, and the address of the next page where there is one.