/** * @fileoverview Server-side JSONLogic evaluation for searches scoped by * OBSIDIAN_READ_PATHS or OBSIDIAN_DENY_PATHS. The caller's tree runs here, on * a worker thread, over the readable notes alone, instead of upstream over the * whole vault: no hit, result, or error reads a note outside the read scope. * The notes carry no link fields: which note a link resolves to is Obsidian's * vault-wide resolution, so `links`, `backlinks`, and `unresolvedLinks` would * change with notes outside the scope (#165). A tree that names one fails with * `link_fields_unavailable` before the search makes a request. * * Every evaluation is bounded — tree depth, work budgets the worker enforces * (per note for what each note's evaluation builds, per search for what kept * results hold past a 1,024-character allowance each), and a wall-clock * deadline — and an evaluation past a bound fails with `logic_too_costly` * rather than holding the process. A note nested too deep to hand to the * worker fails with `note_too_deep`. * * @module services/obsidian/jsonlogic-evaluator */ import type { NoteContext } from './jsonlogic-worker.js'; import type { StructuredSearchHit } from './types.js'; /** * Deepest object/array nesting a tree may have. The plugin evaluates every * shape to at least 5,000 levels; this stays well under the depth at which * Node's structured clone overflows the stack handing a tree to the worker * (about 3,500 levels). */ export declare const MAX_TREE_DEPTH = 1000; /** * Work units kept results may hold across one search, every batch included * (see the worker's `chargeKept`). A result whose JSON is at most 1,024 * characters is kept free, whatever its note; a larger one pays for what its * JSON holds beyond its own note's JSON. Kept results live until the search * answers, so this bounds what an evaluation retains, since Bun ignores the * worker's `resourceLimits`. What a note's evaluation builds and drops is * bounded per note by {@link NOTE_BUILD_UNITS}; evaluation steps that build * nothing are bounded by {@link EVALUATION_DEADLINE_MS}, so a tree that only * tests note fields spends nothing however many notes it reads. */ export declare const KEPT_RESULT_UNITS = 10000000; /** * Work units one note's evaluation may build beyond the note's own size (see * the worker's `charge`): the size of every value `merge`, `cat`, or `map` * builds and of every value an operator places in an array literal. The * allowance resets for each note, since what an evaluation builds is dropped * when it ends, so a tree that builds from every note of a broad scope is * bounded by its largest note rather than by the scope's total. Adding the * note's own size means one copy of a note always fits, at any size a batch * carries; the fixed part leaves room for dozens of copies of a 200 KB note * while holding what one evaluation can allocate to the note plus * 10,000,000 units. */ export declare const NOTE_BUILD_UNITS = 10000000; /** Wall-clock ceiling on one search's evaluation, across its batches, worker startup included. */ export declare const EVALUATION_DEADLINE_MS = 10000; /** * Whether the plugin would read note bodies for `logic`: its own rule, a * substring test for `"content"` on the tree's JSON. A tree without it sees * `content` as `""` upstream, so a scoped fetch mirrors the same rule to keep * results identical — and it is conservative, firing on the word anywhere. */ export declare function readsContent(logic: unknown): boolean; /** * Reject a tree nested deeper than {@link MAX_TREE_DEPTH} before it reaches * anything recursive (serialization, the worker hand-off, evaluation). */ export declare function assertTreeDepth(logic: unknown): void; /** * Reject a tree that reads a link field of the note through `var`, `missing`, * or `missing_some`. A scoped search's notes carry none, so such a read would * see `null` on every note: `{"in": [X, {"var": "backlinks"}]}` would answer * "nothing links here", and `{"missing": ["backlinks"]}` would report the * field missing everywhere. Only a key fixed by the tree is caught — * `"links"`, `"backlinks.0"`, the array form with a default — while a computed * key reads `null`, and a `var` or `missing` applied to the elements a `map`, * `filter`, `reduce`, `all`, `some`, or `none` walks reads the element, not * the note. An object of other than one key is data json-logic-js never * evaluates. Iterative; the tree's depth is already held to * {@link MAX_TREE_DEPTH}. */ export declare function assertNoLinkFields(logic: unknown): void; /** One search's evaluation; see {@link createJsonLogicEvaluation}. */ export interface JsonLogicEvaluation { /** Terminate the worker, if one started. Idempotent; the search calls it however it ends. */ close(): Promise; /** Evaluate the next batch of readable notes, in vault order. */ evaluate(notes: NoteContext[]): Promise; } /** * One search's evaluation of `logic`. `evaluate` takes the readable notes in * vault order, all at once or in successive batches; the budget for kept * results and the deadline span every batch, and each note's build allowance * is its own, so batching changes memory use, not results. * Each call returns the batch's hits as the plugin's search would: a hit for * every truthy result, results shaped by a JSON round trip. It throws * `logic_invalid` when the tree fails on a note, `logic_too_costly` past * either budget or the deadline, `note_too_deep` for a note the worker * hand-off cannot carry, and the abort reason when `signal` aborts first. * * One worker evaluates every batch: started with the first batch that holds a * note, it is terminated when a batch fails, passes a bound, or is cancelled, * and otherwise by `close`. */ export declare function createJsonLogicEvaluation(logic: unknown, opts?: { signal?: AbortSignal | undefined; deadlineMs?: number; }): JsonLogicEvaluation; //# sourceMappingURL=jsonlogic-evaluator.d.ts.map