/** * @file * * Mock of Obsidian's `FileValue`, the Bases value wrapping a vault file. */ import type { FileValue as FileValueOriginal } from 'obsidian'; import type { App } from './App.cjs'; import type { ObjectValue } from './ObjectValue.cjs'; import type { RenderContext } from './RenderContext.cjs'; import type { TFile } from './TFile.cjs'; import type { Value } from './Value.cjs'; import { ListValue } from './ListValue.cjs'; import { NotNullValue } from './NotNullValue.cjs'; /** * Mock of Obsidian's `FileValue`: a non-null value wrapping a file. */ export declare class FileValue extends NotNullValue { app: App; file: TFile; /** * The value type's identifier, `'File'` - Obsidian's own name for this class of value. */ static type: string; /** * The lucide icon name standing for this value's type. */ icon: string; /** * The five accessors' memos, each filled by its accessor's first call and never invalidated, exactly as * Obsidian's `_cachedLinks` and its four siblings are. They keep their unprefixed names because they are * private implementation detail rather than mocked members (L8), and the staleness is the point: a value * read before the vault changed goes on answering what it answered then, in the mock as in the app. */ private cachedBacklinks; private cachedEmbeds; private cachedLinks; private cachedProps; private cachedTags; /** * Creates a file value. * * @param app - The app the file belongs to. * @param file - The wrapped file. */ constructor(app: App, file: TFile); /** * Mock-only factory: creates a file value, spyable via `vi.spyOn(FileValue, 'create__')`. * * @param app - The app the file belongs to. * @param file - The wrapped file. * @returns The new file value. */ static create__(app: App, file: TFile): FileValue; /** * Mock-only: views a value typed as Obsidian's `FileValue` as this mock. * * @param value - The value typed as the original `FileValue`. * @returns The same object, typed as the mock. */ static fromOriginalType3__(value: FileValueOriginal): FileValue; /** * Mock-only: views this mock as Obsidian's `FileValue` type. * * @returns The same object, typed as the original `FileValue`. */ asOriginalType3__(): FileValueOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(FileValue.prototype, 'constructor3__')`. * * @param _app - The app the value was created with. * @param _file - The file the value was created with. */ constructor3__(_app: App, _file: TFile): void; /** * Compares this file with another, as Obsidian does: by `TFile` IDENTITY, not by path. * * Two `FileValue`s built from the same path therefore compare unequal unless the vault handed both the * same `TFile` — which it does, since a vault keeps one `TFile` per path, but a hand-built `TFile` in a * test does not. * * @param other - The file value to compare with. * @returns Whether both wrap the same `TFile` object. */ equals(other: this): boolean; /** * Gets the links pointing AT the wrapped file. * * Obsidian walks the metadata cache's whole `resolvedLinks` graph on every call that is not answered * from the memo, so a backlink appears as soon as the source note is indexed — no separate backlink * index is consulted. Only RESOLVED links count: a link that matches no file is not a backlink to * anything. * * @returns A list of `LinkValue`s, one per source note that links here, in the graph's own insertion * order. Each targets the SOURCE note's path, carries an empty source path — so resolving it is * resolving an absolute path — and shows the source note's short name. A note linking here twice * appears once. Memoized: the first call's list is returned forever after, as Obsidian's is. */ getBacklinks(): ListValue; /** * Gets the file's embeds. * * @returns A list of `LinkValue`s, one per embed in the file's cached metadata, in the order the * parser found them. An unindexed file gives an empty list. Memoized, as {@link FileValue.getBacklinks} * is. */ getEmbeds(): ListValue; /** * Gets the links going OUT of the file. * * A one-line walk over {@link MetadataCache.iterateRefsForFile}, exactly as Obsidian writes it, so the * order is that method's own — frontmatter links, then body links, then embeds. An embed therefore * counts as an outgoing link and appears in both this list and {@link FileValue.getEmbeds}. Unlike * {@link FileValue.getBacklinks} this reads the file's own cache rather than the link graph, so a link * that resolves to nothing is still listed. * * @returns A list of `LinkValue`s. An unindexed file gives an empty list. Memoized, as * {@link FileValue.getBacklinks} is. */ getLinks(): ListValue; /** * Gets the file's frontmatter properties. * * @returns An `ObjectValue` over a shallow copy of the frontmatter, carrying the frontmatter evaluator * that reads a string property as a wikilink, a URL or a date and a `tags` property as a list of tags. * An unindexed file, or one with no frontmatter, gives an empty object value. Memoized, as * {@link FileValue.getBacklinks} is. */ getProps(): ObjectValue; /** * Gets the file's tags. * * @returns A {@link TagsListValue} — declared `ListValue` because that is what `obsidian.d.ts` declares, * and Obsidian answers the same subclass here — holding the file's body tags followed by its frontmatter * tags, each `#`-prefixed and duplicates dropped. An unindexed file gives an empty list. Memoized, as * {@link FileValue.getBacklinks} is. */ getTags(): ListValue; /** * Tells whether the value counts as true in a Bases formula. * * @returns Always `true`: a file value is never empty. */ isTruthy(): boolean; /** * Lists the property keys {@link FileValue.objectAccess} answers for. * * @returns The inherited keys followed by Obsidian's fifteen file keys, every one of which * {@link FileValue.objectAccess} answers. */ keys(): string[]; /** * Loosely compares this file with a value of any type, as Obsidian does: against a `StringValue` holding * this file's path. * * Nothing else loosely equals a file from THIS side - not another `FileValue`, which is why two values * wrapping different `TFile`s of one path stay unequal. A `LinkValue` resolving here does match, but * through its own override, which {@link Value.looseEquals} reaches by trying both directions. * * @param other - The value to compare with. * @returns Whether `other` is a `StringValue` holding this file's full path. */ looseEquals(other: Value): boolean; /** * Reads a named property of the wrapped file. * * @param key - The property key, matched without regard to case. * @returns This value itself for `file`; the file's display name, basename, full name, path, folder path * or extension as a `StringValue`; its creation or modification time as a `DateValue`; its size as a * `NumberValue`; the lists {@link FileValue.getLinks}, {@link FileValue.getEmbeds}, * {@link FileValue.getBacklinks} and {@link FileValue.getTags} build for `links`, `embeds`, `backlinks` * and `tags`; the object {@link FileValue.getProps} builds for `properties`; and otherwise whatever the * base answers. * @throws {Error} For `folder` when the file has no parent folder, where Obsidian reads it unguarded. */ objectAccess(key: string): null | Value; /** * Renders the file into an element, as Obsidian does: through {@link RenderContext.renderFileLink}, which * builds the internal link the app shows. * * The `TFile` itself is handed over rather than its path, so the link resolves by identity and never has to * be looked up - which is also why it can never render as unresolved. No display value is passed, so the * link shows the file's short name. * * @param el - The element to render into. * @param context - The rendering context, which owns the link markup. */ renderTo(el: HTMLElement, context: RenderContext): void; /** * Renders the value as a string. * * @returns The wrapped file's vault path. */ toString(): string; }