query.match
Deterministic selector-based search returning mutation-grade addresses and text ranges. Use this to discover targets before any mutation.
doc.query.match(…)Usage
Typechecked against the public Document API. Runtime validation is tracked separately.
import type { DocumentApi } from '@superdoc/document-api';
export async function commentOnOneClause(doc: DocumentApi) {
const result = await doc.query.match({
select: { type: 'text', pattern: 'Confidential Information' },
require: 'exactlyOne',
});
const match = result.items[0];
if (!match || match.matchKind !== 'text') throw new Error('The clause was not found.');
const receipt = await doc.comments.create(
{ text: 'Please review this definition.', target: match.target },
{ expectedRevision: result.evaluatedRevision },
);
if (!receipt.success) throw new Error(receipt.failure.message);
return receipt;
}Expected result
Returns a QueryMatchOutput with the resolved target address and cardinality metadata.
Inputs
selecttext | noderequiredSearch selector. Use {type:'text', pattern:'...'} for text search or {type:'node', nodeType:'paragraph'|'heading'|...} for node search.
text
type"text"requiredMust be 'text' for text pattern search.
patternstringrequiredText to match. In regex mode, patterns are validated for syntax, maximum length, and safety before execution.
mode"contains" | "regex"Match mode: 'contains' (literal substring, recommended for literal text) or 'regex' (validated regular expression).
caseSensitivebooleanCase-sensitive matching. Default: false.
wholeWordbooleanRequire word-boundary matches. Default: false.
node
type"node"requiredMust be 'node' for node type search.
nodeType"paragraph" | "heading" | "listItem" | "table" | "tableRow" | "tableCell" | "tableOfContents" | "image" | "sdt" | "run" | "bookmark" | "comment" | "hyperlink" | "footnoteRef" | "endnoteRef" | "crossRef" | "indexEntry" | "citation" | "authorityEntry" | "sequenceField" | "tab" | "lineBreak"Block type to match (paragraph, heading, table, listItem, etc.).
kind"block" | "inline"Filter: 'block' or 'inline'.
require"any" | "first" | "exactlyOne" | "all"Match cardinality: 'any' (all matches), 'first' (only first), 'exactlyOne' (fail if != 1), 'all' (fail if 0).
withinBlockNodeAddressLimit search scope to within a specific block: {kind:'block', nodeType:'...', nodeId:'...'}.
Fields
kind"block"requirednodeType"paragraph" | "heading" | "listItem" | "table" | "tableRow" | "tableCell" | "tableOfContents" | "image" | "sdt"requirednodeIdstringrequiredstoryStoryLocatorStory scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.
body
kind"story"requiredstoryType"body"requiredheaderFooterSlot
kind"story"requiredstoryType"headerFooterSlot"requiredsectionSectionAddressrequiredheaderFooterKind"header" | "footer"requiredvariant"default" | "first" | "even"requiredresolution"effective" | "explicit"onWrite"materializeIfInherited" | "editResolvedPart" | "error"headerFooterPart
kind"story"requiredstoryType"headerFooterPart"requiredrefIdstringrequiredfootnote
kind"story"requiredstoryType"footnote"requirednoteIdstringrequiredendnote
kind"story"requiredstoryType"endnote"requirednoteIdstringrequiredtextbox
kind"story"requiredstoryType"textbox"requiredtextboxIdstringrequiredinStoryLocatorStory scope. Defaults to document body when omitted. Use {kind:'story', storyType:'body'} for body, or other storyType values for headers, footers, footnotes, endnotes.
body
kind"story"requiredstoryType"body"requiredheaderFooterSlot
kind"story"requiredstoryType"headerFooterSlot"requiredsectionSectionAddressrequiredFields
kind"section"requiredsectionIdstringrequiredheaderFooterKind"header" | "footer"requiredvariant"default" | "first" | "even"requiredresolution"effective" | "explicit"onWrite"materializeIfInherited" | "editResolvedPart" | "error"headerFooterPart
kind"story"requiredstoryType"headerFooterPart"requiredrefIdstringrequiredfootnote
kind"story"requiredstoryType"footnote"requirednoteIdstringrequiredendnote
kind"story"requiredstoryType"endnote"requirednoteIdstringrequiredtextbox
kind"story"requiredstoryType"textbox"requiredtextboxIdstringrequiredlimitintegerMaximum number of matches to return.
offsetintegerNumber of matches to skip for pagination.
2 additional input fields
mode"strict" | "candidates"Search mode: 'strict' (default, exact matching) or 'candidates' (returns scored potential matches).
includeNodesbooleanWhen true, includes full node data in results. Default: false.
Result
Output fields
evaluatedRevisionstringrequiredtotalintegerrequireditemstext | node[]requiredpagePageInforequiredFields
limitintegerrequiredoffsetintegerrequiredreturnedintegerrequiredmetaobjectrequiredFields
effectiveResolvedbooleanrequiredFailures
Pre-apply throws
MATCH_NOT_FOUNDAMBIGUOUS_MATCHINVALID_INPUT
6 more codes
INTERNAL_ERRORSTORY_NOT_FOUNDSTORY_MISMATCHSTORY_NOT_SUPPORTEDCROSS_STORY_PLANMATERIALIZATION_FAILED
Related
Raw schemas
Open the generated JSON artifact for the exact input, output, success, and failure schemas represented by this contract version.
View raw JSON schemas