1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Node kinds classified as data-access patterns.
//!
//! These node kinds correspond to the `data_access` category in the
//! [`PatternCatalog`](crate::catalog::PatternCatalog).
use LazyLock;
use Regex;
/// Tree-sitter node kinds for data-access patterns.
///
/// - `call_expression`: function/method calls that access data stores or
/// external resources (TypeScript/JavaScript/Go: `fetch`, `query`, `read`,
/// `write`, `db.*`, `sql.*`, etc.). All `call_expression` nodes are
/// classified here; callee-name narrowing is the consumer's responsibility.
/// - `call`: Python function calls accessing data (`cursor.*`, `session.*`,
/// `open`). Same broad-classification rule as above.
pub const NODE_KINDS: & = &;
// TypeScript / JavaScript / Go:
// ^(fetch|axios)\b — top-level fetch/axios calls
// \b(query|read|write|get|post|put|delete|patch)\( — method calls by name
// \b(db|sql)\. — db.* and sql.* receiver calls
// \.(query|read|write|fetch)\( — chained method calls
// ^ anchors the first alternative only; \b guards the rest from false prefixes.
static TS_JS_GO_RE: = new;
// Python:
// ^ anchors each alternative to the start of the text.
// open( — built-in file open
// requests. / httpx. / cursor. / session. / conn. — common data-access libs
static PYTHON_RE: = new;
/// Return `true` when `text` looks like a data-access callee for `language`.
///
/// Rust and Java always return `false` in v0 — data-access detection for those
/// languages is library-shaped (`sqlx::query!`, `reqwest::get`) and deferred to
/// a future regex pass. TypeScript, JavaScript, and Go share one regex table;
/// Python has its own.
///
/// # Examples
///
/// ```rust
/// use sdivi_patterns::queries::data_access::matches_callee;
///
/// assert!(matches_callee("fetch(\"/api/users\")", "typescript"));
/// assert!(matches_callee("cursor.execute(sql)", "python"));
/// assert!(!matches_callee("Math.max(a, b)", "typescript"));
/// assert!(!matches_callee("len(x)", "python"));
/// ```