Document apiReferenceQuery

query.match

Deterministic selector-based search returning mutation-grade addresses and text ranges. Use this to discover targets before any mutation.

read-onlyidempotent
doc.query.match(…)

Usage

Typechecked example

Typechecked against the public Document API. Runtime validation is tracked separately.

Find one clause and create a revision-guarded comment
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 | noderequired

Search selector. Use {type:'text', pattern:'...'} for text search or {type:'node', nodeType:'paragraph'|'heading'|...} for node search.

text
type"text"required

Must be 'text' for text pattern search.

patternstringrequired

Text 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).

caseSensitiveboolean

Case-sensitive matching. Default: false.

wholeWordboolean

Require word-boundary matches. Default: false.

node
type"node"required

Must 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).

withinBlockNodeAddress

Limit search scope to within a specific block: {kind:'block', nodeType:'...', nodeId:'...'}.

Fields
kind"block"required
nodeType"paragraph" | "heading" | "listItem" | "table" | "tableRow" | "tableCell" | "tableOfContents" | "image" | "sdt"required
nodeIdstringrequired
storyStoryLocator

Story 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"required
storyType"body"required
headerFooterSlot
kind"story"required
storyType"headerFooterSlot"required
sectionSectionAddressrequired
headerFooterKind"header" | "footer"required
variant"default" | "first" | "even"required
resolution"effective" | "explicit"
onWrite"materializeIfInherited" | "editResolvedPart" | "error"
headerFooterPart
kind"story"required
storyType"headerFooterPart"required
refIdstringrequired
footnote
kind"story"required
storyType"footnote"required
noteIdstringrequired
endnote
kind"story"required
storyType"endnote"required
noteIdstringrequired
textbox
kind"story"required
storyType"textbox"required
textboxIdstringrequired
inStoryLocator

Story 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"required
storyType"body"required
headerFooterSlot
kind"story"required
storyType"headerFooterSlot"required
sectionSectionAddressrequired
Fields
kind"section"required
sectionIdstringrequired
headerFooterKind"header" | "footer"required
variant"default" | "first" | "even"required
resolution"effective" | "explicit"
onWrite"materializeIfInherited" | "editResolvedPart" | "error"
headerFooterPart
kind"story"required
storyType"headerFooterPart"required
refIdstringrequired
footnote
kind"story"required
storyType"footnote"required
noteIdstringrequired
endnote
kind"story"required
storyType"endnote"required
noteIdstringrequired
textbox
kind"story"required
storyType"textbox"required
textboxIdstringrequired
limitinteger

Maximum number of matches to return.

offsetinteger

Number 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).

includeNodesboolean

When true, includes full node data in results. Default: false.

Result

Output fields
evaluatedRevisionstringrequired
totalintegerrequired
itemstext | node[]required
pagePageInforequired
Fields
limitintegerrequired
offsetintegerrequired
returnedintegerrequired
metaobjectrequired
Fields
effectiveResolvedbooleanrequired

Failures

Pre-apply throws

  • MATCH_NOT_FOUND
  • AMBIGUOUS_MATCH
  • INVALID_INPUT
6 more codes
  • INTERNAL_ERROR
  • STORY_NOT_FOUND
  • STORY_MISMATCH
  • STORY_NOT_SUPPORTED
  • CROSS_STORY_PLAN
  • MATERIALIZATION_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